u2a 3.5.1 → 3.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,188 +1,188 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const os = require('os');
4
- const Logger = require('./logger');
5
- const { secureExec } = require('./securexec');
6
-
7
- const logger = new Logger('osIntegration');
8
-
9
- function createWindowsShortcut(appInfo) {
10
- try {
11
- const { appName, appDir, iconPath } = appInfo;
12
- const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps');
13
-
14
- if (!fs.existsSync(startMenuPath)) {
15
- fs.mkdirSync(startMenuPath, { recursive: true });
16
- }
17
-
18
- const shortcutPath = path.join(startMenuPath, `${appName}.lnk`);
19
- const targetPath = path.join(appDir, 'node_modules', '.bin', 'electron.cmd');
20
- const workingDir = appDir;
21
-
22
- const psScript = `
23
- $WshShell = New-Object -comObject WScript.Shell
24
- $Shortcut = $WshShell.CreateShortcut("${shortcutPath.replace(/\\/g, '\\\\')}")
25
- $Shortcut.TargetPath = "${targetPath.replace(/\\/g, '\\\\')}"
26
- $Shortcut.Arguments = "."
27
- $Shortcut.WorkingDirectory = "${workingDir.replace(/\\/g, '\\\\')}"
28
- $Shortcut.IconLocation = "${iconPath.replace(/\\/g, '\\\\')}"
29
- $Shortcut.Description = "Application Web pour ${appName}"
30
- $Shortcut.Save()
31
- `;
32
-
33
- const tempScriptPath = path.join(os.tmpdir(), `create_shortcut_${appName}.ps1`);
34
- fs.writeFileSync(tempScriptPath, psScript);
35
-
36
- secureExec(`powershell -ExecutionPolicy Bypass -File "${tempScriptPath}"`, {
37
- stdio: ['ignore', 'pipe', 'pipe'],
38
- windowsHide: true
39
- });
40
-
41
- fs.unlinkSync(tempScriptPath);
42
-
43
- logger.success(`Shortcut created in the Start Menu: ${shortcutPath}`);
44
- return shortcutPath;
45
- } catch (error) {
46
- logger.error(`Error while creating the Windows shortcut`, error);
47
- return null;
48
- }
49
- }
50
-
51
- function createLinuxDesktopEntry(appInfo) {
52
- try {
53
- const { appName, url, appDir, iconPath } = appInfo;
54
- const appsDir = path.join(os.homedir(), '.local', 'share', 'applications');
55
-
56
- if (!fs.existsSync(appsDir)) {
57
- fs.mkdirSync(appsDir, { recursive: true });
58
- }
59
-
60
- const desktopEntry = `[Desktop Entry]
61
- Type=Application
62
- Name=${appName}
63
- Exec=${path.join(appDir, 'node_modules', '.bin', 'electron')} ${path.join(appDir, 'main.js')}
64
- Icon=${iconPath}
65
- Comment=Application Web pour ${url}
66
- Categories=Network;WebBrowser;
67
- Terminal=false
68
- `;
69
-
70
- const desktopFilePath = path.join(appsDir, `u2a-${appName}.desktop`);
71
- fs.writeFileSync(desktopFilePath, desktopEntry);
72
-
73
- fs.chmodSync(desktopFilePath, '755');
74
-
75
- logger.success(`Desktop entry created for Linux: ${desktopFilePath}`);
76
- return desktopFilePath;
77
- } catch (error) {
78
- logger.error(`Error while creating the Linux desktop entry`, error);
79
- return null;
80
- }
81
- }
82
-
83
- function createMacOSApp(appInfo) {
84
- try {
85
- const { appName, appDir, iconPath } = appInfo;
86
- const appsDir = path.join(os.homedir(), 'Applications', 'U2A Apps');
87
-
88
- if (!fs.existsSync(appsDir)) {
89
- fs.mkdirSync(appsDir, { recursive: true });
90
- }
91
-
92
- const appPath = path.join(appsDir, `${appName}.app`);
93
- const macOsPath = path.join(appPath, 'Contents', 'MacOS');
94
- const resourcesPath = path.join(appPath, 'Contents', 'Resources');
95
-
96
- fs.mkdirSync(path.join(appPath, 'Contents', 'MacOS'), { recursive: true });
97
- fs.mkdirSync(resourcesPath, { recursive: true });
98
-
99
- const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
100
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
101
- <plist version="1.0">
102
- <dict>
103
- <key>CFBundleExecutable</key>
104
- <string>AppRunner</string>
105
- <key>CFBundleIconFile</key>
106
- <string>icon.icns</string>
107
- <key>CFBundleIdentifier</key>
108
- <string>com.u2a.${appName.replace(/\s+/g, '-')}</string>
109
- <key>CFBundleName</key>
110
- <string>${appName}</string>
111
- <key>CFBundleDisplayName</key>
112
- <string>${appName}</string>
113
- <key>CFBundlePackageType</key>
114
- <string>APPL</string>
115
- <key>CFBundleVersion</key>
116
- <string>1.0</string>
117
- <key>CFBundleShortVersionString</key>
118
- <string>1.0</string>
119
- </dict>
120
- </plist>`;
121
-
122
- fs.writeFileSync(path.join(appPath, 'Contents', 'Info.plist'), infoPlist);
123
-
124
- const shellScript = `#!/bin/bash
125
- cd "${appDir}"
126
- "${path.join(appDir, 'node_modules', '.bin', 'electron')}" "${path.join(appDir, 'main.js')}"`;
127
-
128
- const shellScriptPath = path.join(macOsPath, 'AppRunner');
129
- fs.writeFileSync(shellScriptPath, shellScript);
130
- fs.chmodSync(shellScriptPath, '755');
131
-
132
- fs.copyFileSync(iconPath, path.join(resourcesPath, 'icon.icns'));
133
-
134
- logger.success(`macOS application created: ${appPath}`);
135
- return appPath;
136
- } catch (error) {
137
- logger.error(`Error while creating the macOS application`, error);
138
- return null;
139
- }
140
- }
141
-
142
- function addAppToOS(appName, url, appDir, iconPath) {
143
- const appInfo = { appName, url, appDir, iconPath };
144
- let desktopPath = null;
145
-
146
- if (process.platform === 'win32') {
147
- desktopPath = createWindowsShortcut(appInfo);
148
- } else if (process.platform === 'darwin') {
149
- desktopPath = createMacOSApp(appInfo);
150
- } else if (process.platform === 'linux') {
151
- desktopPath = createLinuxDesktopEntry(appInfo);
152
- } else {
153
- logger.warn(`Desktop integration not supported for platform ${process.platform}`);
154
- }
155
-
156
- return desktopPath;
157
- }
158
-
159
- function removeAppFromOS(appName) {
160
- try {
161
- if (process.platform === 'win32') {
162
- const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps', `${appName}.lnk`);
163
- if (fs.existsSync(startMenuPath)) {
164
- fs.unlinkSync(startMenuPath);
165
- logger.success(`Shortcut removed from the Start Menu: ${startMenuPath}`);
166
- }
167
- } else if (process.platform === 'darwin') {
168
- const appPath = path.join(os.homedir(), 'Applications', 'U2A Apps', `${appName}.app`);
169
- if (fs.existsSync(appPath)) {
170
- fs.rmSync(appPath, { recursive: true, force: true });
171
- logger.success(`macOS application removed: ${appPath}`);
172
- }
173
- } else if (process.platform === 'linux') {
174
- const desktopFilePath = path.join(os.homedir(), '.local', 'share', 'applications', `u2a-${appName}.desktop`);
175
- if (fs.existsSync(desktopFilePath)) {
176
- fs.unlinkSync(desktopFilePath);
177
- logger.success(`Linux desktop entry removed: ${desktopFilePath}`);
178
- }
179
- }
180
- } catch (error) {
181
- logger.error(`Error while removing desktop integration for ${appName}`, error);
182
- }
183
- }
184
-
185
- module.exports = {
186
- addAppToOS,
187
- removeAppFromOS
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+ const Logger = require('./logger');
5
+ const { secureExec } = require('./securexec');
6
+
7
+ const logger = new Logger('osIntegration');
8
+
9
+ function createWindowsShortcut(appInfo) {
10
+ try {
11
+ const { appName, appDir, iconPath } = appInfo;
12
+ const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps');
13
+
14
+ if (!fs.existsSync(startMenuPath)) {
15
+ fs.mkdirSync(startMenuPath, { recursive: true });
16
+ }
17
+
18
+ const shortcutPath = path.join(startMenuPath, `${appName}.lnk`);
19
+ const targetPath = path.join(appDir, 'node_modules', '.bin', 'electron.cmd');
20
+ const workingDir = appDir;
21
+
22
+ const psScript = `
23
+ $WshShell = New-Object -comObject WScript.Shell
24
+ $Shortcut = $WshShell.CreateShortcut("${shortcutPath.replace(/\\/g, '\\\\')}")
25
+ $Shortcut.TargetPath = "${targetPath.replace(/\\/g, '\\\\')}"
26
+ $Shortcut.Arguments = "."
27
+ $Shortcut.WorkingDirectory = "${workingDir.replace(/\\/g, '\\\\')}"
28
+ $Shortcut.IconLocation = "${iconPath.replace(/\\/g, '\\\\')}"
29
+ $Shortcut.Description = "Application Web pour ${appName}"
30
+ $Shortcut.Save()
31
+ `;
32
+
33
+ const tempScriptPath = path.join(os.tmpdir(), `create_shortcut_${appName}.ps1`);
34
+ fs.writeFileSync(tempScriptPath, psScript);
35
+
36
+ secureExec(`powershell -ExecutionPolicy Bypass -File "${tempScriptPath}"`, {
37
+ stdio: ['ignore', 'pipe', 'pipe'],
38
+ windowsHide: true
39
+ });
40
+
41
+ fs.unlinkSync(tempScriptPath);
42
+
43
+ logger.success(`Shortcut created in the Start Menu: ${shortcutPath}`);
44
+ return shortcutPath;
45
+ } catch (error) {
46
+ logger.error(`Error while creating the Windows shortcut`, error);
47
+ return null;
48
+ }
49
+ }
50
+
51
+ function createLinuxDesktopEntry(appInfo) {
52
+ try {
53
+ const { appName, url, appDir, iconPath } = appInfo;
54
+ const appsDir = path.join(os.homedir(), '.local', 'share', 'applications');
55
+
56
+ if (!fs.existsSync(appsDir)) {
57
+ fs.mkdirSync(appsDir, { recursive: true });
58
+ }
59
+
60
+ const desktopEntry = `[Desktop Entry]
61
+ Type=Application
62
+ Name=${appName}
63
+ Exec=${path.join(appDir, 'node_modules', '.bin', 'electron')} ${path.join(appDir, 'main.js')}
64
+ Icon=${iconPath}
65
+ Comment=Application Web pour ${url}
66
+ Categories=Network;WebBrowser;
67
+ Terminal=false
68
+ `;
69
+
70
+ const desktopFilePath = path.join(appsDir, `u2a-${appName}.desktop`);
71
+ fs.writeFileSync(desktopFilePath, desktopEntry);
72
+
73
+ fs.chmodSync(desktopFilePath, '755');
74
+
75
+ logger.success(`Desktop entry created for Linux: ${desktopFilePath}`);
76
+ return desktopFilePath;
77
+ } catch (error) {
78
+ logger.error(`Error while creating the Linux desktop entry`, error);
79
+ return null;
80
+ }
81
+ }
82
+
83
+ function createMacOSApp(appInfo) {
84
+ try {
85
+ const { appName, appDir, iconPath } = appInfo;
86
+ const appsDir = path.join(os.homedir(), 'Applications', 'U2A Apps');
87
+
88
+ if (!fs.existsSync(appsDir)) {
89
+ fs.mkdirSync(appsDir, { recursive: true });
90
+ }
91
+
92
+ const appPath = path.join(appsDir, `${appName}.app`);
93
+ const macOsPath = path.join(appPath, 'Contents', 'MacOS');
94
+ const resourcesPath = path.join(appPath, 'Contents', 'Resources');
95
+
96
+ fs.mkdirSync(path.join(appPath, 'Contents', 'MacOS'), { recursive: true });
97
+ fs.mkdirSync(resourcesPath, { recursive: true });
98
+
99
+ const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
100
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
101
+ <plist version="1.0">
102
+ <dict>
103
+ <key>CFBundleExecutable</key>
104
+ <string>AppRunner</string>
105
+ <key>CFBundleIconFile</key>
106
+ <string>icon.icns</string>
107
+ <key>CFBundleIdentifier</key>
108
+ <string>com.u2a.${appName.replace(/\s+/g, '-')}</string>
109
+ <key>CFBundleName</key>
110
+ <string>${appName}</string>
111
+ <key>CFBundleDisplayName</key>
112
+ <string>${appName}</string>
113
+ <key>CFBundlePackageType</key>
114
+ <string>APPL</string>
115
+ <key>CFBundleVersion</key>
116
+ <string>1.0</string>
117
+ <key>CFBundleShortVersionString</key>
118
+ <string>1.0</string>
119
+ </dict>
120
+ </plist>`;
121
+
122
+ fs.writeFileSync(path.join(appPath, 'Contents', 'Info.plist'), infoPlist);
123
+
124
+ const shellScript = `#!/bin/bash
125
+ cd "${appDir}"
126
+ "${path.join(appDir, 'node_modules', '.bin', 'electron')}" "${path.join(appDir, 'main.js')}"`;
127
+
128
+ const shellScriptPath = path.join(macOsPath, 'AppRunner');
129
+ fs.writeFileSync(shellScriptPath, shellScript);
130
+ fs.chmodSync(shellScriptPath, '755');
131
+
132
+ fs.copyFileSync(iconPath, path.join(resourcesPath, 'icon.icns'));
133
+
134
+ logger.success(`macOS application created: ${appPath}`);
135
+ return appPath;
136
+ } catch (error) {
137
+ logger.error(`Error while creating the macOS application`, error);
138
+ return null;
139
+ }
140
+ }
141
+
142
+ function addAppToOS(appName, url, appDir, iconPath) {
143
+ const appInfo = { appName, url, appDir, iconPath };
144
+ let desktopPath = null;
145
+
146
+ if (process.platform === 'win32') {
147
+ desktopPath = createWindowsShortcut(appInfo);
148
+ } else if (process.platform === 'darwin') {
149
+ desktopPath = createMacOSApp(appInfo);
150
+ } else if (process.platform === 'linux') {
151
+ desktopPath = createLinuxDesktopEntry(appInfo);
152
+ } else {
153
+ logger.warn(`Desktop integration not supported for platform ${process.platform}`);
154
+ }
155
+
156
+ return desktopPath;
157
+ }
158
+
159
+ function removeAppFromOS(appName) {
160
+ try {
161
+ if (process.platform === 'win32') {
162
+ const startMenuPath = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'U2A Apps', `${appName}.lnk`);
163
+ if (fs.existsSync(startMenuPath)) {
164
+ fs.unlinkSync(startMenuPath);
165
+ logger.success(`Shortcut removed from the Start Menu: ${startMenuPath}`);
166
+ }
167
+ } else if (process.platform === 'darwin') {
168
+ const appPath = path.join(os.homedir(), 'Applications', 'U2A Apps', `${appName}.app`);
169
+ if (fs.existsSync(appPath)) {
170
+ fs.rmSync(appPath, { recursive: true, force: true });
171
+ logger.success(`macOS application removed: ${appPath}`);
172
+ }
173
+ } else if (process.platform === 'linux') {
174
+ const desktopFilePath = path.join(os.homedir(), '.local', 'share', 'applications', `u2a-${appName}.desktop`);
175
+ if (fs.existsSync(desktopFilePath)) {
176
+ fs.unlinkSync(desktopFilePath);
177
+ logger.success(`Linux desktop entry removed: ${desktopFilePath}`);
178
+ }
179
+ }
180
+ } catch (error) {
181
+ logger.error(`Error while removing desktop integration for ${appName}`, error);
182
+ }
183
+ }
184
+
185
+ module.exports = {
186
+ addAppToOS,
187
+ removeAppFromOS
188
188
  };
@@ -1,120 +1,120 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const axios = require('axios');
4
- const Logger = require('./logger');
5
- const { setupConfig, CONFIG_DIR } = require('./config');
6
- const { initSettings, getSetting } = require('./settings');
7
-
8
- setupConfig(); // builds ~/.u2a/*
9
-
10
- const logger = new Logger('postinstall');
11
- const postinstallJsonPath = path.join(CONFIG_DIR, 'postinstall.json');
12
- let isUpgrade = false;
13
- let currentVersion = '0.0.0'; //0.0.0 for new installations
14
- let sendAnonReports = true; // u2a configure reports disable to disable
15
-
16
- const formatVersionLine = (label, version) => {
17
- // calculates how many spaces we need after the version to have a correct formatting
18
- const baseLength = `; ${label}: `.length + version.length;
19
- const spaceCount = Math.max(0, 30 - baseLength);
20
- const spaces = ' '.repeat(spaceCount);
21
-
22
- return `; ${label}: ${version}${spaces};`;
23
- };
24
-
25
- async function run() {
26
- //check if postinstall.json exists (exists -> update, doesnt -> new install)
27
- if (fs.existsSync(postinstallJsonPath)) {
28
- try {
29
- const postinstallData = JSON.parse(fs.readFileSync(postinstallJsonPath, 'utf8'));
30
- currentVersion = postinstallData.version || '';
31
- isUpgrade = true;
32
-
33
- let newVersion = '';
34
- try {
35
- const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
36
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
37
- newVersion = packageJson.version || '';
38
- } catch (err) {
39
- logger.error(`Error reading package.json for display`, err.message);
40
- newVersion = 'unknown';
41
- }
42
-
43
- logger.info(';=============================;');
44
- logger.info('; u2a has been updated! ;');
45
- logger.info('; Successfully migrated from ;');
46
- logger.info(formatVersionLine('Old version', currentVersion));
47
- logger.info(formatVersionLine('New version', newVersion));
48
- logger.info(';=============================;');
49
-
50
- initSettings();
51
- } catch (err) {
52
- logger.error(`Error reading postinstall.json`, err.message);
53
- isUpgrade = false;
54
- }
55
- }
56
-
57
- const sendAnonReports = getSetting('send_anon_reports');
58
-
59
- // shows this cool message if it isnt an upgrade
60
- if (!isUpgrade) {
61
- logger.info(';=============================;');
62
- logger.info('; Welcome to u2a ! ;');
63
- logger.info('; Thanks for downloading this ;');
64
- logger.info('; tool ! ;');
65
- logger.info('; ;');
66
- logger.info('; Create a local webapp with ;');
67
- logger.info('; \'u2a create <url/domain>\' ;');
68
- logger.info('; ;');
69
- logger.info('; Check docs.urltoapp.xyz for ;');
70
- logger.info('; more detailed usage. ;');
71
- logger.info('; ;');
72
- logger.info('; Note: Anonymous installs ;');
73
- logger.info('; reports are enabled by ;');
74
- logger.info('; default. To disable: ;');
75
- logger.info('; \'u2a configure reports ;');
76
- logger.info('; disable\' ;');
77
- logger.info(';=============================;');
78
-
79
- initSettings(true);
80
- }
81
-
82
- const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
83
- let newVersion = '';
84
-
85
- try {
86
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
87
- newVersion = packageJson.version || '';
88
- } catch (err) {
89
- logger.error(`Error reading package.json`, err.message);
90
- }
91
-
92
- if (sendAnonReports) {
93
- try {
94
-
95
- const params = new URLSearchParams({
96
- previousVersion: currentVersion,
97
- newVersion: newVersion
98
- });
99
-
100
- // backend here https://github.com/url2app/urltoapp.xyz/blob/main/api/v1/api/reports.php
101
- await axios.get(`https://urltoapp.xyz/api/v1/reports?${params.toString()}`);
102
- logger.debug('Anonymous usage report sent');
103
- } catch (err) {
104
- logger.debug(`Failed to send anonymous report: ${err.message}`);
105
- }
106
- }
107
-
108
- try {
109
- fs.writeFileSync(postinstallJsonPath, JSON.stringify({
110
- version: newVersion,
111
- installed_at: new Date().toISOString()
112
- }, null, 2));
113
- } catch (err) {
114
- logger.error(`Error updating postinstall.json`, err.message);
115
- }
116
- }
117
-
118
- run().catch(err => {
119
- logger.error(`Unexpected error`, err.message);
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const axios = require('axios');
4
+ const Logger = require('./logger');
5
+ const { setupConfig, CONFIG_DIR } = require('./config');
6
+ const { initSettings, getSetting } = require('./settings');
7
+
8
+ setupConfig(); // builds ~/.u2a/*
9
+
10
+ const logger = new Logger('postinstall');
11
+ const postinstallJsonPath = path.join(CONFIG_DIR, 'postinstall.json');
12
+ let isUpgrade = false;
13
+ let currentVersion = '0.0.0'; //0.0.0 for new installations
14
+ let sendAnonReports = true; // u2a configure reports disable to disable
15
+
16
+ const formatVersionLine = (label, version) => {
17
+ // calculates how many spaces we need after the version to have a correct formatting
18
+ const baseLength = `; ${label}: `.length + version.length;
19
+ const spaceCount = Math.max(0, 30 - baseLength);
20
+ const spaces = ' '.repeat(spaceCount);
21
+
22
+ return `; ${label}: ${version}${spaces};`;
23
+ };
24
+
25
+ async function run() {
26
+ //check if postinstall.json exists (exists -> update, doesnt -> new install)
27
+ if (fs.existsSync(postinstallJsonPath)) {
28
+ try {
29
+ const postinstallData = JSON.parse(fs.readFileSync(postinstallJsonPath, 'utf8'));
30
+ currentVersion = postinstallData.version || '';
31
+ isUpgrade = true;
32
+
33
+ let newVersion = '';
34
+ try {
35
+ const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
36
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
37
+ newVersion = packageJson.version || '';
38
+ } catch (err) {
39
+ logger.error(`Error reading package.json for display`, err.message);
40
+ newVersion = 'unknown';
41
+ }
42
+
43
+ logger.info(';=============================;');
44
+ logger.info('; u2a has been updated! ;');
45
+ logger.info('; Successfully migrated from ;');
46
+ logger.info(formatVersionLine('Old version', currentVersion));
47
+ logger.info(formatVersionLine('New version', newVersion));
48
+ logger.info(';=============================;');
49
+
50
+ initSettings();
51
+ } catch (err) {
52
+ logger.error(`Error reading postinstall.json`, err.message);
53
+ isUpgrade = false;
54
+ }
55
+ }
56
+
57
+ const sendAnonReports = getSetting('send_anon_reports');
58
+
59
+ // shows this cool message if it isnt an upgrade
60
+ if (!isUpgrade) {
61
+ logger.info(';=============================;');
62
+ logger.info('; Welcome to u2a ! ;');
63
+ logger.info('; Thanks for downloading this ;');
64
+ logger.info('; tool ! ;');
65
+ logger.info('; ;');
66
+ logger.info('; Create a local webapp with ;');
67
+ logger.info('; \'u2a create <url/domain>\' ;');
68
+ logger.info('; ;');
69
+ logger.info('; Check docs.urltoapp.xyz for ;');
70
+ logger.info('; more detailed usage. ;');
71
+ logger.info('; ;');
72
+ logger.info('; Note: Anonymous installs ;');
73
+ logger.info('; reports are enabled by ;');
74
+ logger.info('; default. To disable: ;');
75
+ logger.info('; \'u2a configure reports ;');
76
+ logger.info('; disable\' ;');
77
+ logger.info(';=============================;');
78
+
79
+ initSettings(true);
80
+ }
81
+
82
+ const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
83
+ let newVersion = '';
84
+
85
+ try {
86
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
87
+ newVersion = packageJson.version || '';
88
+ } catch (err) {
89
+ logger.error(`Error reading package.json`, err.message);
90
+ }
91
+
92
+ if (sendAnonReports) {
93
+ try {
94
+
95
+ const params = new URLSearchParams({
96
+ previousVersion: currentVersion,
97
+ newVersion: newVersion
98
+ });
99
+
100
+ // backend here https://github.com/url2app/urltoapp.xyz/blob/main/api/v1/api/reports.php
101
+ await axios.get(`https://urltoapp.xyz/api/v1/reports?${params.toString()}`);
102
+ logger.debug('Anonymous usage report sent');
103
+ } catch (err) {
104
+ logger.debug(`Failed to send anonymous report: ${err.message}`);
105
+ }
106
+ }
107
+
108
+ try {
109
+ fs.writeFileSync(postinstallJsonPath, JSON.stringify({
110
+ version: newVersion,
111
+ installed_at: new Date().toISOString()
112
+ }, null, 2));
113
+ } catch (err) {
114
+ logger.error(`Error updating postinstall.json`, err.message);
115
+ }
116
+ }
117
+
118
+ run().catch(err => {
119
+ logger.error(`Unexpected error`, err.message);
120
120
  });
@@ -1,21 +1,21 @@
1
- const Logger = require('./logger');
2
- const logger = new Logger('sanitize');
3
-
4
-
5
- function sanitizeInput(userInput) {
6
- const sInput = userInput.replace(/[^a-zA-Z0-9_\-.\s:/@%]/g, '_');
7
- logger.debug(`Original content: ${userInput} | Sanitized content: ${sInput}`);
8
- return sInput;
9
- }
10
-
11
- function sanitizeCommand(command) {
12
- const sCommand = command.replace(/[^\w\-.:/@\\ ="']/g, '_');
13
- logger.debug(`Original content: ${command} | Sanitized content: ${sCommand}`);
14
- return sCommand;
15
- }
16
-
17
-
18
- module.exports = {
19
- sanitizeInput,
20
- sanitizeCommand
1
+ const Logger = require('./logger');
2
+ const logger = new Logger('sanitize');
3
+
4
+
5
+ function sanitizeInput(userInput) {
6
+ const sInput = userInput.replace(/[^a-zA-Z0-9_\-.\s:/@%]/g, '_');
7
+ logger.debug(`Original content: ${userInput} | Sanitized content: ${sInput}`);
8
+ return sInput;
9
+ }
10
+
11
+ function sanitizeCommand(command) {
12
+ const sCommand = command.replace(/[^\w\-.:/@\\ ="']/g, '_');
13
+ logger.debug(`Original content: ${command} | Sanitized content: ${sCommand}`);
14
+ return sCommand;
15
+ }
16
+
17
+
18
+ module.exports = {
19
+ sanitizeInput,
20
+ sanitizeCommand
21
21
  }