| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/network-web/articleparse.cpp`/ |
| 2 | |
| 3 | #include "network-web/articleparse.h"cxx . . $ `<file>/src/librssguard/network-web/articleparse.h`/ |
| 4 | |
| 5 | #include "3rd-party/boolinq/boolinq.h"cxx . . $ `<file>/src/librssguard/3rd-party/boolinq/boolinq.h`/ |
| 6 | #include "exceptions/applicationexception.h"cxx . . $ `<file>/src/librssguard/exceptions/applicationexception.h`/ |
| 7 | #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/ |
| 8 | |
| 9 | #include <QDir> |
| 10 | |
| 11 | #define EXTRACTOR_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:11:9`! "@extractus/article-extractor" |
| 12 | #define EXTRACTOR_VERSIONcxx . . $ `src/librssguard/network-web/articleparse.cpp:12:9`! "8.0.7" |
| 13 | |
| 14 | #define FETCH_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:14:9`! "fetch-charset-detection" |
| 15 | #define FETCH_VERSIONcxx . . $ `src/librssguard/network-web/articleparse.cpp:15:9`! "1.0.1" |
| 16 | |
| 17 | ArticleParsecxx . . $ ArticleParse#::ArticleParsecxx . . $ ArticleParse#ArticleParse(749de1b6ae65bddd).(QObjectcxx . . $ QObject#* parent) : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).{parent}, m_modulesInstallingcxx . . $ ArticleParse#m_modulesInstalling.(false), m_modulesInstalledcxx . . $ ArticleParse#m_modulesInstalled.(false) { |
| 18 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).(), &NodeJscxx . . $ NodeJs#::packageInstalledUpdatedcxx . . $ NodeJs#packageInstalledUpdated(34ac6af3085f0564)., this, &ArticleParsecxx . . $ ArticleParse#::onPackageReadycxx . . $ ArticleParse#onPackageReady(34ac6af3085f0564).); |
| 19 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).(), &NodeJscxx . . $ NodeJs#::packageErrorcxx . . $ NodeJs#packageError(c66daf909bbebbbc)., this, &ArticleParsecxx . . $ ArticleParse#::onPackageErrorcxx . . $ ArticleParse#onPackageError(c66daf909bbebbbc).); |
| 20 | } |
| 21 | |
| 22 | void ArticleParsecxx . . $ ArticleParse#::onPackageReadycxx . . $ ArticleParse#onPackageReady(34ac6af3085f0564).(const QObjectcxx . . $ QObject#* sndr, |
| 23 | const QListcxx . . $ QList#<NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#>& pkgs, |
| 24 | bool already_up_to_date) { |
| 25 | Q_UNUSEDcxx . . $ `<external>/17563275351362271547/qtpreprocessorsupport.h:20:9`!(already_up_to_date) |
| 26 | |
| 27 | bool concerns_extractor = boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(pkgs).anycxx . . $ boolinq/Linq#any(992a0234366b9b4f).([cxx . . $ std/function#function(bdc3712e480e4d04).](const NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#& pkg) { |
| 28 | return pkg.m_namecxx . . $ NodeJs#PackageMetadata#m_name. ==cxx . . $ `operator==`(5bc2975d2d751687). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(EXTRACTOR_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:11:9`!); |
| 29 | }); |
| 30 | |
| 31 | if (!concerns_extractor) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | m_modulesInstalledcxx . . $ ArticleParse#m_modulesInstalled. = true; |
| 36 | m_modulesInstallingcxx . . $ ArticleParse#m_modulesInstalling. = false; |
| 37 | |
| 38 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::NodePackageUpdatedcxx . . $ Notification#Event#NodePackageUpdated., |
| 39 | {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Packages for article-extractor are installed"), |
| 40 | trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Reload your website or article and you can test it then!"), |
| 41 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Informationcxx . . $ QSystemTrayIcon#Information.}, |
| 42 | {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).true, true, false}); |
| 43 | |
| 44 | // Emit this just to allow the action again for user. |
| 45 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! errorOnArticleParsingcxx . . $ ArticleParse#errorOnArticleParsing(4e4c9b6f049ed725).(sndr, trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Packages for article-extractor are installed. You can now use this feature!")); |
| 46 | } |
| 47 | |
| 48 | void ArticleParsecxx . . $ ArticleParse#::onPackageErrorcxx . . $ ArticleParse#onPackageError(c66daf909bbebbbc).(const QObjectcxx . . $ QObject#* sndr, |
| 49 | const QListcxx . . $ QList#<NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#>& pkgs, |
| 50 | const QStringcxx . . $ QString#& error) { |
| 51 | bool concerns_extractor = boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(pkgs).anycxx . . $ boolinq/Linq#any(992a0234366b9b4f).([cxx . . $ std/function#function(bdc3712e480e4d04).](const NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#& pkg) { |
| 52 | return pkg.m_namecxx . . $ NodeJs#PackageMetadata#m_name. ==cxx . . $ `operator==`(5bc2975d2d751687). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(EXTRACTOR_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:11:9`!); |
| 53 | }); |
| 54 | |
| 55 | if (!concerns_extractor) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | m_modulesInstalledcxx . . $ ArticleParse#m_modulesInstalled. = m_modulesInstallingcxx . . $ ArticleParse#m_modulesInstalling. = false; |
| 60 | |
| 61 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::NodePackageUpdatedcxx . . $ Notification#Event#NodePackageUpdated., |
| 62 | {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Packages for article-extractor are NOT installed"), |
| 63 | trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("There is error: %1").argcxx . . $ QString#arg(ad0bca07273edcc2).(error), |
| 64 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Criticalcxx . . $ QSystemTrayIcon#Critical.}, |
| 65 | {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).true, true, false}); |
| 66 | |
| 67 | // Emit this just to allow readability again for user. |
| 68 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! errorOnArticleParsingcxx . . $ ArticleParse#errorOnArticleParsing(4e4c9b6f049ed725).(sndr, |
| 69 | trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Packages for article-extractor are NOT installed. There is error: %1").argcxx . . $ QString#arg(ad0bca07273edcc2).(error)); |
| 70 | } |
| 71 | |
| 72 | void ArticleParsecxx . . $ ArticleParse#::parseArticlecxx . . $ ArticleParse#parseArticle(c8761f536c0fe045).(QObjectcxx . . $ QObject#* sndr, const QStringcxx . . $ QString#& url) { |
| 73 | if (!m_modulesInstalledcxx . . $ ArticleParse#m_modulesInstalled.) { |
| 74 | // NOTE: Here we use MJS file directly placed in its NODE package folder |
| 75 | // because NODE_PATH is not supported for MJS files. |
| 76 | m_scriptFilenamecxx . . $ ArticleParse#m_scriptFilename. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->processedPackageFoldercxx . . $ NodeJs#processedPackageFolder(6ef7b6c27b00b43d).() +cxx . . $ operator+(adfbdceb504720ce). QDircxx . . $ QDir#::separatorcxx . . $ QDir#separator(44eb9225326fcbf5).() +cxx . . $ operator+(adfbdceb504720ce). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("extract-article.mjs"); |
| 77 | |
| 78 | if (!IOFactorycxx . . $ IOFactory#::copyFilecxx . . $ IOFactory#copyFile(edf9e4f73813982f).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(":/scripts/article-extractor/extract-article.mjs"), m_scriptFilenamecxx . . $ ArticleParse#m_scriptFilename.)) { |
| 79 | qCriticalNNcxx . . $ `src/librssguard/definitions/definitions.h:421:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_ADBLOCKcxx . . $ `src/librssguard/definitions/definitions.h:169:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Failed to copy article-extractor script to TEMP."; |
| 80 | } |
| 81 | |
| 82 | try { |
| 83 | NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus# st_extractor = |
| 84 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->packageStatuscxx . . $ NodeJs#packageStatus(bc4ac2c1878ad842).({QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(EXTRACTOR_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:11:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(EXTRACTOR_VERSIONcxx . . $ `src/librssguard/network-web/articleparse.cpp:12:9`!)}); |
| 85 | NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus# st_fetch = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->packageStatuscxx . . $ NodeJs#packageStatus(bc4ac2c1878ad842).({QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(FETCH_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:14:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(FETCH_VERSIONcxx . . $ `src/librssguard/network-web/articleparse.cpp:15:9`!)}); |
| 86 | |
| 87 | if (st_extractor != NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus#::UpToDatecxx . . $ NodeJs#PackageStatus#UpToDate. || st_fetch != NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus#::UpToDatecxx . . $ NodeJs#PackageStatus#UpToDate.) { |
| 88 | if (!m_modulesInstallingcxx . . $ ArticleParse#m_modulesInstalling.) { |
| 89 | // We make sure to update modules. |
| 90 | m_modulesInstallingcxx . . $ ArticleParse#m_modulesInstalling. = true; |
| 91 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->installUpdatePackagescxx . . $ NodeJs#installUpdatePackages(b5245139ef44c0df).(sndr, |
| 92 | {cxx . . $ QList#QList(b6da5b9a9f304025).{QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(EXTRACTOR_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:11:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(EXTRACTOR_VERSIONcxx . . $ `src/librssguard/network-web/articleparse.cpp:12:9`!)}, |
| 93 | {QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(FETCH_PACKAGEcxx . . $ `src/librssguard/network-web/articleparse.cpp:14:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(FETCH_VERSIONcxx . . $ `src/librssguard/network-web/articleparse.cpp:15:9`!)}}); |
| 94 | } |
| 95 | |
| 96 | return; |
| 97 | } |
| 98 | else { |
| 99 | m_modulesInstalledcxx . . $ ArticleParse#m_modulesInstalled. = true; |
| 100 | } |
| 101 | } |
| 102 | catch (const ApplicationExceptioncxx . . $ ApplicationException#& ex) { |
| 103 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::NodePackageUpdatedcxx . . $ Notification#Event#NodePackageUpdated., |
| 104 | {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Node.js libraries not installed"), |
| 105 | trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Node.js is not configured properly. Go to \"Settings\" -> \"Node.js\" and check " |
| 106 | "if your Node.js is properly configured."), |
| 107 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Criticalcxx . . $ QSystemTrayIcon#Critical.}, |
| 108 | {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).true, true, false}); |
| 109 | |
| 110 | qCriticalNNcxx . . $ `src/librssguard/definitions/definitions.h:421:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_COREcxx . . $ `src/librssguard/definitions/definitions.h:178:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Failed to check for Node.js package status:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(ex.message()); |
| 111 | |
| 112 | // Emit this just to allow readability again for user. |
| 113 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! articleParsedcxx . . $ ArticleParse#articleParsed(ba727f494339005a).(sndr, |
| 114 | url, |
| 115 | trcxx . . $ ArticleParse#tr(75d9f1c324b4579d).("Node.js is not configured properly. Go to \"Settings\" -> \"Node.js\" and check " |
| 116 | "if your Node.js is properly configured.")); |
| 117 | return; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | QProcesscxx . . $ QProcess#* proc = new QProcesscxx . . $ QProcess#QProcess(749de1b6ae65bddd).(this); |
| 122 | |
| 123 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(proc, |
| 124 | QOverloadcxx . . $ QOverload#<int, QProcess::ExitStatus>::ofcxx . . $ QOverload#of(8e142c06a530e2ab).(&QProcesscxx . . $ QProcess#::finishedcxx . . $ QProcess#finished(15c350e1a5203cbf).), |
| 125 | this, |
| 126 | [=](int exit_code, QProcesscxx . . $ QProcess#::ExitStatuscxx . . $ QProcess#ExitStatus# exit_status) { |
| 127 | onParsingFinishedcxx . . $ ArticleParse#onParsingFinished(f52d3a8f93c5d3b6).(sndr, url, exit_code, exit_status); |
| 128 | }); |
| 129 | |
| 130 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->runScriptcxx . . $ NodeJs#runScript(b32167958b67e3d).(proc, m_scriptFilenamecxx . . $ ArticleParse#m_scriptFilename., {cxx . . $ QList#QList(b6da5b9a9f304025).url}); |
| 131 | } |
| 132 | |
| 133 | void ArticleParsecxx . . $ ArticleParse#::onParsingFinishedcxx . . $ ArticleParse#onParsingFinished(f52d3a8f93c5d3b6).(const QObjectcxx . . $ QObject# *sndr, |
| 134 | const QStringcxx . . $ QString#& url, |
| 135 | int exit_code, |
| 136 | QProcesscxx . . $ QProcess#::ExitStatuscxx . . $ QProcess#ExitStatus# exit_status) { |
| 137 | QProcesscxx . . $ QProcess#* proc = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<QProcesscxx . . $ QProcess#*>(sendercxx . . $ QObject#sender(2dbb680a34285c44).()); |
| 138 | |
| 139 | if (exit_status == QProcesscxx . . $ QProcess#::ExitStatuscxx . . $ QProcess#ExitStatus#::NormalExitcxx . . $ QProcess#NormalExit. && exit_code == EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!) { |
| 140 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! articleParsedcxx . . $ ArticleParse#articleParsed(ba727f494339005a).(sndr, url, QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(4e15edac36d215be).(proc->readAllStandardOutputcxx . . $ QProcess#readAllStandardOutput(b3c286cec66e09f4).())); |
| 141 | } |
| 142 | else { |
| 143 | QStringcxx . . $ QString# err = QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(4e15edac36d215be).(proc->readAllStandardErrorcxx . . $ QProcess#readAllStandardError(b3c286cec66e09f4).()); |
| 144 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! errorOnArticleParsingcxx . . $ ArticleParse#errorOnArticleParsing(4e4c9b6f049ed725).(sndr, err); |
| 145 | } |
| 146 | |
| 147 | proc->deleteLatercxx . . $ QObject#deleteLater(49f6e7a06ebc5aa8).(); |
| 148 | } |