pinme 2.0.2-beta.4 → 2.0.2-beta.6
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.
- package/dist/index.js +310 -306
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96,9 +96,9 @@ var require_package = __commonJS({
|
|
|
96
96
|
// node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js
|
|
97
97
|
var require_main = __commonJS({
|
|
98
98
|
"node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js"(exports2, module2) {
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
var
|
|
99
|
+
var fs16 = require("fs");
|
|
100
|
+
var path17 = require("path");
|
|
101
|
+
var os5 = require("os");
|
|
102
102
|
var crypto3 = require("crypto");
|
|
103
103
|
var packageJson = require_package();
|
|
104
104
|
var version2 = packageJson.version;
|
|
@@ -200,7 +200,7 @@ var require_main = __commonJS({
|
|
|
200
200
|
if (options && options.path && options.path.length > 0) {
|
|
201
201
|
if (Array.isArray(options.path)) {
|
|
202
202
|
for (const filepath of options.path) {
|
|
203
|
-
if (
|
|
203
|
+
if (fs16.existsSync(filepath)) {
|
|
204
204
|
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
@@ -208,15 +208,15 @@ var require_main = __commonJS({
|
|
|
208
208
|
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
209
209
|
}
|
|
210
210
|
} else {
|
|
211
|
-
possibleVaultPath =
|
|
211
|
+
possibleVaultPath = path17.resolve(process.cwd(), ".env.vault");
|
|
212
212
|
}
|
|
213
|
-
if (
|
|
213
|
+
if (fs16.existsSync(possibleVaultPath)) {
|
|
214
214
|
return possibleVaultPath;
|
|
215
215
|
}
|
|
216
216
|
return null;
|
|
217
217
|
}
|
|
218
218
|
function _resolveHome(envPath) {
|
|
219
|
-
return envPath[0] === "~" ?
|
|
219
|
+
return envPath[0] === "~" ? path17.join(os5.homedir(), envPath.slice(1)) : envPath;
|
|
220
220
|
}
|
|
221
221
|
function _configVault(options) {
|
|
222
222
|
const debug = Boolean(options && options.debug);
|
|
@@ -232,7 +232,7 @@ var require_main = __commonJS({
|
|
|
232
232
|
return { parsed };
|
|
233
233
|
}
|
|
234
234
|
function configDotenv(options) {
|
|
235
|
-
const dotenvPath =
|
|
235
|
+
const dotenvPath = path17.resolve(process.cwd(), ".env");
|
|
236
236
|
let encoding = "utf8";
|
|
237
237
|
const debug = Boolean(options && options.debug);
|
|
238
238
|
if (options && options.encoding) {
|
|
@@ -255,13 +255,13 @@ var require_main = __commonJS({
|
|
|
255
255
|
}
|
|
256
256
|
let lastError;
|
|
257
257
|
const parsedAll = {};
|
|
258
|
-
for (const
|
|
258
|
+
for (const path18 of optionPaths) {
|
|
259
259
|
try {
|
|
260
|
-
const parsed = DotenvModule.parse(
|
|
260
|
+
const parsed = DotenvModule.parse(fs16.readFileSync(path18, { encoding }));
|
|
261
261
|
DotenvModule.populate(parsedAll, parsed, options);
|
|
262
262
|
} catch (e) {
|
|
263
263
|
if (debug) {
|
|
264
|
-
_debug(`Failed to load ${
|
|
264
|
+
_debug(`Failed to load ${path18} ${e.message}`);
|
|
265
265
|
}
|
|
266
266
|
lastError = e;
|
|
267
267
|
}
|
|
@@ -810,7 +810,7 @@ var require_has_flag = __commonJS({
|
|
|
810
810
|
var require_supports_color = __commonJS({
|
|
811
811
|
"node_modules/.pnpm/supports-color@5.5.0/node_modules/supports-color/index.js"(exports2, module2) {
|
|
812
812
|
"use strict";
|
|
813
|
-
var
|
|
813
|
+
var os5 = require("os");
|
|
814
814
|
var hasFlag = require_has_flag();
|
|
815
815
|
var env = process.env;
|
|
816
816
|
var forceColor;
|
|
@@ -848,7 +848,7 @@ var require_supports_color = __commonJS({
|
|
|
848
848
|
}
|
|
849
849
|
const min = forceColor ? 1 : 0;
|
|
850
850
|
if (process.platform === "win32") {
|
|
851
|
-
const osRelease =
|
|
851
|
+
const osRelease = os5.release().split(".");
|
|
852
852
|
if (Number(process.versions.node.split(".")[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
853
853
|
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
854
854
|
}
|
|
@@ -1523,10 +1523,10 @@ var import_chalk25 = __toESM(require("chalk"));
|
|
|
1523
1523
|
var import_figlet5 = __toESM(require("figlet"));
|
|
1524
1524
|
|
|
1525
1525
|
// package.json
|
|
1526
|
-
var version = "2.0.2-beta.
|
|
1526
|
+
var version = "2.0.2-beta.6";
|
|
1527
1527
|
|
|
1528
1528
|
// bin/upload.ts
|
|
1529
|
-
var
|
|
1529
|
+
var import_path6 = __toESM(require("path"));
|
|
1530
1530
|
var import_chalk5 = __toESM(require("chalk"));
|
|
1531
1531
|
var import_inquirer = __toESM(require("inquirer"));
|
|
1532
1532
|
var import_figlet = __toESM(require("figlet"));
|
|
@@ -1972,9 +1972,9 @@ function isVisitable(thing) {
|
|
|
1972
1972
|
function removeBrackets(key) {
|
|
1973
1973
|
return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
|
|
1974
1974
|
}
|
|
1975
|
-
function renderKey(
|
|
1976
|
-
if (!
|
|
1977
|
-
return
|
|
1975
|
+
function renderKey(path17, key, dots) {
|
|
1976
|
+
if (!path17) return key;
|
|
1977
|
+
return path17.concat(key).map(function each(token, i) {
|
|
1978
1978
|
token = removeBrackets(token);
|
|
1979
1979
|
return !dots && i ? "[" + token + "]" : token;
|
|
1980
1980
|
}).join(dots ? "." : "");
|
|
@@ -2019,9 +2019,9 @@ function toFormData(obj, formData, options) {
|
|
|
2019
2019
|
}
|
|
2020
2020
|
return value;
|
|
2021
2021
|
}
|
|
2022
|
-
function defaultVisitor(value, key,
|
|
2022
|
+
function defaultVisitor(value, key, path17) {
|
|
2023
2023
|
let arr = value;
|
|
2024
|
-
if (value && !
|
|
2024
|
+
if (value && !path17 && typeof value === "object") {
|
|
2025
2025
|
if (utils_default.endsWith(key, "{}")) {
|
|
2026
2026
|
key = metaTokens ? key : key.slice(0, -2);
|
|
2027
2027
|
value = JSON.stringify(value);
|
|
@@ -2040,7 +2040,7 @@ function toFormData(obj, formData, options) {
|
|
|
2040
2040
|
if (isVisitable(value)) {
|
|
2041
2041
|
return true;
|
|
2042
2042
|
}
|
|
2043
|
-
formData.append(renderKey(
|
|
2043
|
+
formData.append(renderKey(path17, key, dots), convertValue(value));
|
|
2044
2044
|
return false;
|
|
2045
2045
|
}
|
|
2046
2046
|
const stack = [];
|
|
@@ -2049,10 +2049,10 @@ function toFormData(obj, formData, options) {
|
|
|
2049
2049
|
convertValue,
|
|
2050
2050
|
isVisitable
|
|
2051
2051
|
});
|
|
2052
|
-
function build(value,
|
|
2052
|
+
function build(value, path17) {
|
|
2053
2053
|
if (utils_default.isUndefined(value)) return;
|
|
2054
2054
|
if (stack.indexOf(value) !== -1) {
|
|
2055
|
-
throw Error("Circular reference detected in " +
|
|
2055
|
+
throw Error("Circular reference detected in " + path17.join("."));
|
|
2056
2056
|
}
|
|
2057
2057
|
stack.push(value);
|
|
2058
2058
|
utils_default.forEach(value, function each(el, key) {
|
|
@@ -2060,11 +2060,11 @@ function toFormData(obj, formData, options) {
|
|
|
2060
2060
|
formData,
|
|
2061
2061
|
el,
|
|
2062
2062
|
utils_default.isString(key) ? key.trim() : key,
|
|
2063
|
-
|
|
2063
|
+
path17,
|
|
2064
2064
|
exposedHelpers
|
|
2065
2065
|
);
|
|
2066
2066
|
if (result === true) {
|
|
2067
|
-
build(el,
|
|
2067
|
+
build(el, path17 ? path17.concat(key) : [key]);
|
|
2068
2068
|
}
|
|
2069
2069
|
});
|
|
2070
2070
|
stack.pop();
|
|
@@ -2225,7 +2225,7 @@ var node_default = {
|
|
|
2225
2225
|
// node_modules/.pnpm/axios@1.3.2/node_modules/axios/lib/helpers/toURLEncodedForm.js
|
|
2226
2226
|
function toURLEncodedForm(data, options) {
|
|
2227
2227
|
return toFormData_default(data, new node_default.classes.URLSearchParams(), Object.assign({
|
|
2228
|
-
visitor: function(value, key,
|
|
2228
|
+
visitor: function(value, key, path17, helpers) {
|
|
2229
2229
|
if (node_default.isNode && utils_default.isBuffer(value)) {
|
|
2230
2230
|
this.append(key, value.toString("base64"));
|
|
2231
2231
|
return false;
|
|
@@ -2254,10 +2254,10 @@ function arrayToObject(arr) {
|
|
|
2254
2254
|
return obj;
|
|
2255
2255
|
}
|
|
2256
2256
|
function formDataToJSON(formData) {
|
|
2257
|
-
function buildPath(
|
|
2258
|
-
let name =
|
|
2257
|
+
function buildPath(path17, value, target, index) {
|
|
2258
|
+
let name = path17[index++];
|
|
2259
2259
|
const isNumericKey = Number.isFinite(+name);
|
|
2260
|
-
const isLast = index >=
|
|
2260
|
+
const isLast = index >= path17.length;
|
|
2261
2261
|
name = !name && utils_default.isArray(target) ? target.length : name;
|
|
2262
2262
|
if (isLast) {
|
|
2263
2263
|
if (utils_default.hasOwnProp(target, name)) {
|
|
@@ -2270,7 +2270,7 @@ function formDataToJSON(formData) {
|
|
|
2270
2270
|
if (!target[name] || !utils_default.isObject(target[name])) {
|
|
2271
2271
|
target[name] = [];
|
|
2272
2272
|
}
|
|
2273
|
-
const result = buildPath(
|
|
2273
|
+
const result = buildPath(path17, value, target[name], index);
|
|
2274
2274
|
if (result && utils_default.isArray(target[name])) {
|
|
2275
2275
|
target[name] = arrayToObject(target[name]);
|
|
2276
2276
|
}
|
|
@@ -3332,9 +3332,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
3332
3332
|
auth = urlUsername + ":" + urlPassword;
|
|
3333
3333
|
}
|
|
3334
3334
|
auth && headers.delete("authorization");
|
|
3335
|
-
let
|
|
3335
|
+
let path17;
|
|
3336
3336
|
try {
|
|
3337
|
-
|
|
3337
|
+
path17 = buildURL(
|
|
3338
3338
|
parsed.pathname + parsed.search,
|
|
3339
3339
|
config.params,
|
|
3340
3340
|
config.paramsSerializer
|
|
@@ -3352,7 +3352,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
3352
3352
|
false
|
|
3353
3353
|
);
|
|
3354
3354
|
const options = {
|
|
3355
|
-
path:
|
|
3355
|
+
path: path17,
|
|
3356
3356
|
method,
|
|
3357
3357
|
headers: headers.toJSON(),
|
|
3358
3358
|
agents: { http: config.httpAgent, https: config.httpsAgent },
|
|
@@ -3571,14 +3571,14 @@ var cookies_default = node_default.isStandardBrowserEnv ? (
|
|
|
3571
3571
|
// Standard browser envs support document.cookie
|
|
3572
3572
|
/* @__PURE__ */ function standardBrowserEnv() {
|
|
3573
3573
|
return {
|
|
3574
|
-
write: function write(name, value, expires,
|
|
3574
|
+
write: function write(name, value, expires, path17, domain, secure) {
|
|
3575
3575
|
const cookie = [];
|
|
3576
3576
|
cookie.push(name + "=" + encodeURIComponent(value));
|
|
3577
3577
|
if (utils_default.isNumber(expires)) {
|
|
3578
3578
|
cookie.push("expires=" + new Date(expires).toGMTString());
|
|
3579
3579
|
}
|
|
3580
|
-
if (utils_default.isString(
|
|
3581
|
-
cookie.push("path=" +
|
|
3580
|
+
if (utils_default.isString(path17)) {
|
|
3581
|
+
cookie.push("path=" + path17);
|
|
3582
3582
|
}
|
|
3583
3583
|
if (utils_default.isString(domain)) {
|
|
3584
3584
|
cookie.push("domain=" + domain);
|
|
@@ -5263,44 +5263,25 @@ function validateDnsDomain(domain) {
|
|
|
5263
5263
|
var import_crypto_js = __toESM(require("crypto-js"));
|
|
5264
5264
|
|
|
5265
5265
|
// bin/utils/getDeviceId.ts
|
|
5266
|
-
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
5267
|
-
var import_path3 = __toESM(require("path"));
|
|
5268
|
-
var import_os3 = __toESM(require("os"));
|
|
5269
|
-
var import_uuid = require("uuid");
|
|
5270
|
-
|
|
5271
|
-
// bin/utils/auth.ts
|
|
5272
5266
|
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
5273
|
-
var import_os2 = __toESM(require("os"));
|
|
5274
5267
|
var import_path2 = __toESM(require("path"));
|
|
5275
|
-
var
|
|
5276
|
-
var
|
|
5277
|
-
function getAuthConfig2() {
|
|
5278
|
-
try {
|
|
5279
|
-
if (!import_fs_extra2.default.existsSync(AUTH_FILE2)) return null;
|
|
5280
|
-
const data = import_fs_extra2.default.readJsonSync(AUTH_FILE2);
|
|
5281
|
-
if (!(data == null ? void 0 : data.address) || !(data == null ? void 0 : data.token)) return null;
|
|
5282
|
-
return data;
|
|
5283
|
-
} catch {
|
|
5284
|
-
return null;
|
|
5285
|
-
}
|
|
5286
|
-
}
|
|
5287
|
-
|
|
5288
|
-
// bin/utils/getDeviceId.ts
|
|
5268
|
+
var import_os2 = __toESM(require("os"));
|
|
5269
|
+
var import_uuid = require("uuid");
|
|
5289
5270
|
function getDeviceId() {
|
|
5290
|
-
const configDir =
|
|
5291
|
-
const configFile =
|
|
5292
|
-
if (!
|
|
5293
|
-
|
|
5271
|
+
const configDir = import_path2.default.join(import_os2.default.homedir(), ".pinme");
|
|
5272
|
+
const configFile = import_path2.default.join(configDir, "device-id");
|
|
5273
|
+
if (!import_fs_extra2.default.existsSync(configDir)) {
|
|
5274
|
+
import_fs_extra2.default.mkdirSync(configDir, { recursive: true });
|
|
5294
5275
|
}
|
|
5295
|
-
if (
|
|
5296
|
-
return
|
|
5276
|
+
if (import_fs_extra2.default.existsSync(configFile)) {
|
|
5277
|
+
return import_fs_extra2.default.readFileSync(configFile, "utf8").trim();
|
|
5297
5278
|
}
|
|
5298
5279
|
const deviceId = (0, import_uuid.v4)();
|
|
5299
|
-
|
|
5280
|
+
import_fs_extra2.default.writeFileSync(configFile, deviceId);
|
|
5300
5281
|
return deviceId;
|
|
5301
5282
|
}
|
|
5302
5283
|
function getUid() {
|
|
5303
|
-
const auth =
|
|
5284
|
+
const auth = getAuthConfig();
|
|
5304
5285
|
if (auth == null ? void 0 : auth.address) {
|
|
5305
5286
|
return auth.address;
|
|
5306
5287
|
}
|
|
@@ -5308,15 +5289,15 @@ function getUid() {
|
|
|
5308
5289
|
}
|
|
5309
5290
|
|
|
5310
5291
|
// bin/utils/uploadToIpfsSplit.ts
|
|
5311
|
-
var
|
|
5312
|
-
var
|
|
5292
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
5293
|
+
var import_path5 = __toESM(require("path"));
|
|
5313
5294
|
var import_form_data2 = __toESM(require("form-data"));
|
|
5314
5295
|
var import_ora = __toESM(require("ora"));
|
|
5315
5296
|
var crypto2 = __toESM(require("crypto"));
|
|
5316
5297
|
|
|
5317
5298
|
// bin/utils/uploadLimits.ts
|
|
5318
5299
|
var import_fs = __toESM(require("fs"));
|
|
5319
|
-
var
|
|
5300
|
+
var import_path3 = __toESM(require("path"));
|
|
5320
5301
|
var FILE_SIZE_LIMIT = parseInt("500", 10) * 1024 * 1024;
|
|
5321
5302
|
var DIRECTORY_SIZE_LIMIT = parseInt("500", 10) * 1024 * 1024;
|
|
5322
5303
|
function checkFileSizeLimit(filePath) {
|
|
@@ -5339,7 +5320,7 @@ function calculateDirectorySize(directoryPath) {
|
|
|
5339
5320
|
let totalSize = 0;
|
|
5340
5321
|
const files = import_fs.default.readdirSync(directoryPath);
|
|
5341
5322
|
for (const file of files) {
|
|
5342
|
-
const filePath =
|
|
5323
|
+
const filePath = import_path3.default.join(directoryPath, file);
|
|
5343
5324
|
const stats = import_fs.default.statSync(filePath);
|
|
5344
5325
|
if (stats.isFile()) {
|
|
5345
5326
|
totalSize += stats.size;
|
|
@@ -5357,30 +5338,30 @@ function formatSize(bytes) {
|
|
|
5357
5338
|
}
|
|
5358
5339
|
|
|
5359
5340
|
// bin/utils/history.ts
|
|
5360
|
-
var
|
|
5361
|
-
var
|
|
5362
|
-
var
|
|
5341
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
5342
|
+
var import_path4 = __toESM(require("path"));
|
|
5343
|
+
var import_os3 = __toESM(require("os"));
|
|
5363
5344
|
var import_dayjs = __toESM(require("dayjs"));
|
|
5364
5345
|
var import_chalk4 = __toESM(require("chalk"));
|
|
5365
|
-
var HISTORY_DIR =
|
|
5366
|
-
var HISTORY_FILE =
|
|
5346
|
+
var HISTORY_DIR = import_path4.default.join(import_os3.default.homedir(), ".pinme");
|
|
5347
|
+
var HISTORY_FILE = import_path4.default.join(HISTORY_DIR, "upload-history.json");
|
|
5367
5348
|
var ensureHistoryDir = () => {
|
|
5368
|
-
if (!
|
|
5369
|
-
|
|
5349
|
+
if (!import_fs_extra3.default.existsSync(HISTORY_DIR)) {
|
|
5350
|
+
import_fs_extra3.default.mkdirSync(HISTORY_DIR, { recursive: true });
|
|
5370
5351
|
}
|
|
5371
|
-
if (!
|
|
5372
|
-
|
|
5352
|
+
if (!import_fs_extra3.default.existsSync(HISTORY_FILE)) {
|
|
5353
|
+
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, { uploads: [] });
|
|
5373
5354
|
}
|
|
5374
5355
|
};
|
|
5375
5356
|
var saveUploadHistory = (uploadData) => {
|
|
5376
5357
|
try {
|
|
5377
5358
|
ensureHistoryDir();
|
|
5378
|
-
const history =
|
|
5359
|
+
const history = import_fs_extra3.default.readJsonSync(HISTORY_FILE);
|
|
5379
5360
|
const newRecord = {
|
|
5380
5361
|
timestamp: Date.now(),
|
|
5381
5362
|
date: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
|
|
5382
5363
|
path: uploadData.path,
|
|
5383
|
-
filename: uploadData.filename ||
|
|
5364
|
+
filename: uploadData.filename || import_path4.default.basename(uploadData.path),
|
|
5384
5365
|
contentHash: uploadData.contentHash,
|
|
5385
5366
|
previewHash: uploadData.previewHash,
|
|
5386
5367
|
size: uploadData.size,
|
|
@@ -5389,7 +5370,7 @@ var saveUploadHistory = (uploadData) => {
|
|
|
5389
5370
|
shortUrl: (uploadData == null ? void 0 : uploadData.shortUrl) || null
|
|
5390
5371
|
};
|
|
5391
5372
|
history.uploads.unshift(newRecord);
|
|
5392
|
-
|
|
5373
|
+
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, history, { spaces: 2 });
|
|
5393
5374
|
return true;
|
|
5394
5375
|
} catch (error) {
|
|
5395
5376
|
console.error(import_chalk4.default.red(`Error saving upload history: ${error.message}`));
|
|
@@ -5399,7 +5380,7 @@ var saveUploadHistory = (uploadData) => {
|
|
|
5399
5380
|
var getUploadHistory = (limit = 10) => {
|
|
5400
5381
|
try {
|
|
5401
5382
|
ensureHistoryDir();
|
|
5402
|
-
const history =
|
|
5383
|
+
const history = import_fs_extra3.default.readJsonSync(HISTORY_FILE);
|
|
5403
5384
|
return history.uploads.slice(0, limit);
|
|
5404
5385
|
} catch (error) {
|
|
5405
5386
|
console.error(import_chalk4.default.red(`Error reading upload history: ${error.message}`));
|
|
@@ -5439,7 +5420,7 @@ var displayUploadHistory = (limit = 10) => {
|
|
|
5439
5420
|
var clearUploadHistory = () => {
|
|
5440
5421
|
try {
|
|
5441
5422
|
ensureHistoryDir();
|
|
5442
|
-
|
|
5423
|
+
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, { uploads: [] });
|
|
5443
5424
|
console.log(import_chalk4.default.green("Upload history cleared successfully."));
|
|
5444
5425
|
return true;
|
|
5445
5426
|
} catch (error) {
|
|
@@ -5560,7 +5541,7 @@ var StepProgressBar = class {
|
|
|
5560
5541
|
async function calculateMD5(filePath) {
|
|
5561
5542
|
return new Promise((resolve, reject) => {
|
|
5562
5543
|
const hash = crypto2.createHash("md5");
|
|
5563
|
-
const stream4 =
|
|
5544
|
+
const stream4 = import_fs_extra4.default.createReadStream(filePath);
|
|
5564
5545
|
stream4.on("data", hash.update.bind(hash));
|
|
5565
5546
|
stream4.on("end", () => resolve(hash.digest("hex")));
|
|
5566
5547
|
stream4.on("error", reject);
|
|
@@ -5569,20 +5550,20 @@ async function calculateMD5(filePath) {
|
|
|
5569
5550
|
async function compressDirectory(sourcePath) {
|
|
5570
5551
|
return new Promise((resolve, reject) => {
|
|
5571
5552
|
const tempDir = require("os").tmpdir();
|
|
5572
|
-
if (!
|
|
5573
|
-
|
|
5553
|
+
if (!import_fs_extra4.default.existsSync(tempDir)) {
|
|
5554
|
+
import_fs_extra4.default.mkdirSync(tempDir, { recursive: true });
|
|
5574
5555
|
}
|
|
5575
|
-
const outputPath =
|
|
5556
|
+
const outputPath = import_path5.default.join(
|
|
5576
5557
|
tempDir,
|
|
5577
|
-
`pinme_${
|
|
5558
|
+
`pinme_${import_path5.default.basename(sourcePath)}_${Date.now()}.zip`
|
|
5578
5559
|
);
|
|
5579
|
-
const output =
|
|
5560
|
+
const output = import_fs_extra4.default.createWriteStream(outputPath);
|
|
5580
5561
|
const zlib2 = require("zlib");
|
|
5581
5562
|
const gzip = zlib2.createGzip({ level: 9 });
|
|
5582
5563
|
output.on("close", () => resolve(outputPath));
|
|
5583
5564
|
gzip.on("error", reject);
|
|
5584
5565
|
gzip.pipe(output);
|
|
5585
|
-
const stats =
|
|
5566
|
+
const stats = import_fs_extra4.default.statSync(sourcePath);
|
|
5586
5567
|
if (stats.isDirectory()) {
|
|
5587
5568
|
const archive = require("archiver");
|
|
5588
5569
|
const archiveStream = archive("zip", { zlib: { level: 9 } });
|
|
@@ -5591,29 +5572,40 @@ async function compressDirectory(sourcePath) {
|
|
|
5591
5572
|
archiveStream.directory(sourcePath, false);
|
|
5592
5573
|
archiveStream.finalize();
|
|
5593
5574
|
} else {
|
|
5594
|
-
const fileStream =
|
|
5575
|
+
const fileStream = import_fs_extra4.default.createReadStream(sourcePath);
|
|
5595
5576
|
fileStream.pipe(gzip);
|
|
5596
5577
|
}
|
|
5597
5578
|
});
|
|
5598
5579
|
}
|
|
5599
|
-
async function initChunkSession(filePath, deviceId, isDirectory = false) {
|
|
5600
|
-
|
|
5601
|
-
const
|
|
5580
|
+
async function initChunkSession(filePath, deviceId, options = {}, isDirectory = false) {
|
|
5581
|
+
var _a2;
|
|
5582
|
+
const stats = import_fs_extra4.default.statSync(filePath);
|
|
5583
|
+
const fileName = import_path5.default.basename(filePath);
|
|
5602
5584
|
const fileSize = stats.size;
|
|
5603
5585
|
const md5 = await calculateMD5(filePath);
|
|
5604
5586
|
try {
|
|
5587
|
+
const projectName = (_a2 = options.projectName) == null ? void 0 : _a2.trim();
|
|
5588
|
+
let authHeaders = {};
|
|
5589
|
+
const requestBody = {
|
|
5590
|
+
file_name: fileName,
|
|
5591
|
+
file_size: fileSize,
|
|
5592
|
+
md5,
|
|
5593
|
+
is_directory: isDirectory,
|
|
5594
|
+
uid: deviceId
|
|
5595
|
+
};
|
|
5596
|
+
if (projectName) {
|
|
5597
|
+
requestBody.project_name = projectName;
|
|
5598
|
+
authHeaders = getAuthHeaders();
|
|
5599
|
+
}
|
|
5605
5600
|
const response = await axios_default.post(
|
|
5606
5601
|
`${IPFS_API_URL}/chunk/init`,
|
|
5607
|
-
|
|
5608
|
-
file_name: fileName,
|
|
5609
|
-
file_size: fileSize,
|
|
5610
|
-
md5,
|
|
5611
|
-
is_directory: isDirectory,
|
|
5612
|
-
uid: deviceId
|
|
5613
|
-
},
|
|
5602
|
+
requestBody,
|
|
5614
5603
|
{
|
|
5615
5604
|
timeout: TIMEOUT,
|
|
5616
|
-
headers: {
|
|
5605
|
+
headers: {
|
|
5606
|
+
"Content-Type": "application/json",
|
|
5607
|
+
...authHeaders
|
|
5608
|
+
}
|
|
5617
5609
|
}
|
|
5618
5610
|
);
|
|
5619
5611
|
const { code, msg, data } = response.data;
|
|
@@ -5699,7 +5691,7 @@ async function delayWithAbortCheck(delay, signal) {
|
|
|
5699
5691
|
});
|
|
5700
5692
|
}
|
|
5701
5693
|
async function uploadFileChunks(filePath, sessionId, totalChunks, chunkSize, deviceId, progressBar) {
|
|
5702
|
-
const fileData =
|
|
5694
|
+
const fileData = import_fs_extra4.default.readFileSync(filePath);
|
|
5703
5695
|
const abortController = new AbortController();
|
|
5704
5696
|
let completedCount = 0;
|
|
5705
5697
|
let hasFatalError = false;
|
|
@@ -5864,13 +5856,13 @@ async function uploadDirectoryInChunks(directoryPath, deviceId, options = {}) {
|
|
|
5864
5856
|
)} (size: ${formatSize(sizeCheck.size)})`
|
|
5865
5857
|
);
|
|
5866
5858
|
}
|
|
5867
|
-
const progressBar = new StepProgressBar(
|
|
5859
|
+
const progressBar = new StepProgressBar(import_path5.default.basename(directoryPath), true);
|
|
5868
5860
|
try {
|
|
5869
5861
|
progressBar.startStep(0, "Preparing compression");
|
|
5870
5862
|
const compressedPath = await compressDirectory(directoryPath);
|
|
5871
5863
|
progressBar.completeStep();
|
|
5872
5864
|
progressBar.startStep(1, "Initializing session");
|
|
5873
|
-
const sessionInfo = await initChunkSession(compressedPath, deviceId, true);
|
|
5865
|
+
const sessionInfo = await initChunkSession(compressedPath, deviceId, options, true);
|
|
5874
5866
|
progressBar.completeStep();
|
|
5875
5867
|
progressBar.startStep(2, "Chunk upload");
|
|
5876
5868
|
await uploadFileChunks(
|
|
@@ -5893,12 +5885,12 @@ async function uploadDirectoryInChunks(directoryPath, deviceId, options = {}) {
|
|
|
5893
5885
|
const result = await monitorChunkProgress(traceId, deviceId, options, progressBar);
|
|
5894
5886
|
progressBar.completeStep();
|
|
5895
5887
|
try {
|
|
5896
|
-
|
|
5888
|
+
import_fs_extra4.default.unlinkSync(compressedPath);
|
|
5897
5889
|
} catch (error) {
|
|
5898
5890
|
}
|
|
5899
5891
|
const uploadData = {
|
|
5900
5892
|
path: directoryPath,
|
|
5901
|
-
filename:
|
|
5893
|
+
filename: import_path5.default.basename(directoryPath),
|
|
5902
5894
|
contentHash: (result == null ? void 0 : result.hash) || "unknown",
|
|
5903
5895
|
size: sizeCheck.size,
|
|
5904
5896
|
fileCount: 0,
|
|
@@ -5925,11 +5917,11 @@ async function uploadFileInChunks(filePath, deviceId, options = {}) {
|
|
|
5925
5917
|
)} (size: ${formatSize(sizeCheck.size)})`
|
|
5926
5918
|
);
|
|
5927
5919
|
}
|
|
5928
|
-
const fileName =
|
|
5920
|
+
const fileName = import_path5.default.basename(filePath);
|
|
5929
5921
|
const progressBar = new StepProgressBar(fileName, false);
|
|
5930
5922
|
try {
|
|
5931
5923
|
progressBar.startStep(0, "Initializing session");
|
|
5932
|
-
const sessionInfo = await initChunkSession(filePath, deviceId, false);
|
|
5924
|
+
const sessionInfo = await initChunkSession(filePath, deviceId, options, false);
|
|
5933
5925
|
progressBar.completeStep();
|
|
5934
5926
|
progressBar.startStep(1, "Chunk upload");
|
|
5935
5927
|
await uploadFileChunks(
|
|
@@ -5973,13 +5965,14 @@ async function uploadFileInChunks(filePath, deviceId, options = {}) {
|
|
|
5973
5965
|
}
|
|
5974
5966
|
}
|
|
5975
5967
|
async function uploadToIpfsSplit_default(filePath, options = {}) {
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5968
|
+
var _a2;
|
|
5969
|
+
const uid = ((_a2 = options.uid) == null ? void 0 : _a2.trim()) || getUid();
|
|
5970
|
+
if (!uid) {
|
|
5971
|
+
throw new Error("Upload uid not found");
|
|
5979
5972
|
}
|
|
5980
5973
|
try {
|
|
5981
|
-
const isDirectory =
|
|
5982
|
-
const result = isDirectory ? await uploadDirectoryInChunks(filePath,
|
|
5974
|
+
const isDirectory = import_fs_extra4.default.statSync(filePath).isDirectory();
|
|
5975
|
+
const result = isDirectory ? await uploadDirectoryInChunks(filePath, uid, options) : await uploadFileInChunks(filePath, uid, options);
|
|
5983
5976
|
if (result == null ? void 0 : result.hash) {
|
|
5984
5977
|
return {
|
|
5985
5978
|
contentHash: result.hash,
|
|
@@ -6018,9 +6011,9 @@ function formatShortUrl(shortUrl) {
|
|
|
6018
6011
|
}
|
|
6019
6012
|
return `https://${normalized}.pinit.eth.limo`;
|
|
6020
6013
|
}
|
|
6021
|
-
function resolveUploadUrls(contentHash, shortUrl) {
|
|
6022
|
-
const
|
|
6023
|
-
const encryptedCID = encryptHash(contentHash, APP_CONFIG.secretKey,
|
|
6014
|
+
function resolveUploadUrls(contentHash, shortUrl, uid) {
|
|
6015
|
+
const resolvedUid = (uid == null ? void 0 : uid.trim()) || getUid();
|
|
6016
|
+
const encryptedCID = encryptHash(contentHash, APP_CONFIG.secretKey, resolvedUid);
|
|
6024
6017
|
const managementUrl = `${APP_CONFIG.ipfsPreviewUrl}${encryptedCID}`;
|
|
6025
6018
|
const publicUrl = formatShortUrl(shortUrl) || managementUrl;
|
|
6026
6019
|
return {
|
|
@@ -6031,12 +6024,13 @@ function resolveUploadUrls(contentHash, shortUrl) {
|
|
|
6031
6024
|
async function uploadPath(targetPath, options = {}) {
|
|
6032
6025
|
const result = await uploadToIpfsSplit_default(targetPath, {
|
|
6033
6026
|
importAsCar: options.importAsCar,
|
|
6034
|
-
projectName: options.projectName
|
|
6027
|
+
projectName: options.projectName,
|
|
6028
|
+
uid: options.uid
|
|
6035
6029
|
});
|
|
6036
6030
|
if (!(result == null ? void 0 : result.contentHash)) {
|
|
6037
6031
|
throw new Error("Upload failed: no content hash returned");
|
|
6038
6032
|
}
|
|
6039
|
-
const urls = resolveUploadUrls(result.contentHash, result.shortUrl);
|
|
6033
|
+
const urls = resolveUploadUrls(result.contentHash, result.shortUrl, options.uid);
|
|
6040
6034
|
return {
|
|
6041
6035
|
contentHash: result.contentHash,
|
|
6042
6036
|
shortUrl: result.shortUrl,
|
|
@@ -6049,7 +6043,7 @@ async function uploadPath(targetPath, options = {}) {
|
|
|
6049
6043
|
checkNodeVersion();
|
|
6050
6044
|
function checkPathSync(inputPath) {
|
|
6051
6045
|
try {
|
|
6052
|
-
const absolutePath =
|
|
6046
|
+
const absolutePath = import_path6.default.resolve(inputPath);
|
|
6053
6047
|
if (import_fs2.default.existsSync(absolutePath)) {
|
|
6054
6048
|
return absolutePath;
|
|
6055
6049
|
}
|
|
@@ -6141,13 +6135,10 @@ var upload_default = async (options) => {
|
|
|
6141
6135
|
const domainArg = getDomainFromArgs();
|
|
6142
6136
|
const dnsArg = getDnsFromArgs();
|
|
6143
6137
|
const needsAuth = !!domainArg || dnsArg;
|
|
6144
|
-
|
|
6145
|
-
if (needsAuth) {
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
console.log(import_chalk5.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
6149
|
-
return;
|
|
6150
|
-
}
|
|
6138
|
+
const authConfig = getAuthConfig();
|
|
6139
|
+
if (needsAuth && !authConfig) {
|
|
6140
|
+
console.log(import_chalk5.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
6141
|
+
return;
|
|
6151
6142
|
}
|
|
6152
6143
|
const argPath = process.argv[3];
|
|
6153
6144
|
if (argPath && !argPath.startsWith("-")) {
|
|
@@ -6202,7 +6193,8 @@ var upload_default = async (options) => {
|
|
|
6202
6193
|
let result;
|
|
6203
6194
|
try {
|
|
6204
6195
|
result = await uploadPath(absolutePath, {
|
|
6205
|
-
projectName: APP_CONFIG.pinmeProjectName
|
|
6196
|
+
projectName: APP_CONFIG.pinmeProjectName,
|
|
6197
|
+
uid: authConfig == null ? void 0 : authConfig.address
|
|
6206
6198
|
});
|
|
6207
6199
|
} catch (error) {
|
|
6208
6200
|
console.error(import_chalk5.default.red(`Upload error: ${error.message}`));
|
|
@@ -6295,7 +6287,8 @@ var upload_default = async (options) => {
|
|
|
6295
6287
|
let result;
|
|
6296
6288
|
try {
|
|
6297
6289
|
result = await uploadPath(absolutePath, {
|
|
6298
|
-
projectName: APP_CONFIG.pinmeProjectName
|
|
6290
|
+
projectName: APP_CONFIG.pinmeProjectName,
|
|
6291
|
+
uid: authConfig == null ? void 0 : authConfig.address
|
|
6299
6292
|
});
|
|
6300
6293
|
} catch (error) {
|
|
6301
6294
|
console.error(import_chalk5.default.red(`Upload error: ${error.message}`));
|
|
@@ -6336,7 +6329,7 @@ var upload_default = async (options) => {
|
|
|
6336
6329
|
};
|
|
6337
6330
|
|
|
6338
6331
|
// bin/importCar.ts
|
|
6339
|
-
var
|
|
6332
|
+
var import_path7 = __toESM(require("path"));
|
|
6340
6333
|
var import_chalk6 = __toESM(require("chalk"));
|
|
6341
6334
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
6342
6335
|
var import_figlet2 = __toESM(require("figlet"));
|
|
@@ -6359,7 +6352,7 @@ function encryptHash2(contentHash, key, uid) {
|
|
|
6359
6352
|
}
|
|
6360
6353
|
function checkPathSync2(inputPath) {
|
|
6361
6354
|
try {
|
|
6362
|
-
const absolutePath =
|
|
6355
|
+
const absolutePath = import_path7.default.resolve(inputPath);
|
|
6363
6356
|
if (import_fs3.default.existsSync(absolutePath)) {
|
|
6364
6357
|
return absolutePath;
|
|
6365
6358
|
}
|
|
@@ -6413,7 +6406,10 @@ var importCar_default = async (options) => {
|
|
|
6413
6406
|
}
|
|
6414
6407
|
console.log(import_chalk6.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
6415
6408
|
try {
|
|
6416
|
-
const result = await uploadPath(absolutePath, {
|
|
6409
|
+
const result = await uploadPath(absolutePath, {
|
|
6410
|
+
importAsCar: true,
|
|
6411
|
+
uid: getUid2()
|
|
6412
|
+
});
|
|
6417
6413
|
if (result) {
|
|
6418
6414
|
const uid = getUid2();
|
|
6419
6415
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
@@ -6464,7 +6460,10 @@ var importCar_default = async (options) => {
|
|
|
6464
6460
|
}
|
|
6465
6461
|
console.log(import_chalk6.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
6466
6462
|
try {
|
|
6467
|
-
const result = await uploadPath(absolutePath, {
|
|
6463
|
+
const result = await uploadPath(absolutePath, {
|
|
6464
|
+
importAsCar: true,
|
|
6465
|
+
uid: getUid2()
|
|
6466
|
+
});
|
|
6468
6467
|
if (result) {
|
|
6469
6468
|
const uid = getUid2();
|
|
6470
6469
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
@@ -6499,7 +6498,7 @@ var importCar_default = async (options) => {
|
|
|
6499
6498
|
};
|
|
6500
6499
|
|
|
6501
6500
|
// bin/exportCar.ts
|
|
6502
|
-
var
|
|
6501
|
+
var import_path8 = __toESM(require("path"));
|
|
6503
6502
|
var import_chalk7 = __toESM(require("chalk"));
|
|
6504
6503
|
var import_inquirer3 = __toESM(require("inquirer"));
|
|
6505
6504
|
var import_figlet3 = __toESM(require("figlet"));
|
|
@@ -6639,14 +6638,14 @@ var exportCar_default = async () => {
|
|
|
6639
6638
|
]);
|
|
6640
6639
|
outputDir = answer.output.trim() || currentDir;
|
|
6641
6640
|
}
|
|
6642
|
-
outputDir =
|
|
6641
|
+
outputDir = import_path8.default.resolve(outputDir);
|
|
6643
6642
|
if (!import_fs4.default.existsSync(outputDir)) {
|
|
6644
6643
|
import_fs4.default.mkdirSync(outputDir, { recursive: true });
|
|
6645
6644
|
} else if (!import_fs4.default.statSync(outputDir).isDirectory()) {
|
|
6646
6645
|
console.log(import_chalk7.default.red(`Error: ${outputDir} exists but is not a directory.`));
|
|
6647
6646
|
return;
|
|
6648
6647
|
}
|
|
6649
|
-
const finalOutputPath =
|
|
6648
|
+
const finalOutputPath = import_path8.default.join(outputDir, `${cid}.car`);
|
|
6650
6649
|
if (import_fs4.default.existsSync(finalOutputPath)) {
|
|
6651
6650
|
const answer = await import_inquirer3.default.prompt([
|
|
6652
6651
|
{
|
|
@@ -7075,7 +7074,7 @@ async function walletBalanceCmd() {
|
|
|
7075
7074
|
}
|
|
7076
7075
|
|
|
7077
7076
|
// bin/bind.ts
|
|
7078
|
-
var
|
|
7077
|
+
var import_path9 = __toESM(require("path"));
|
|
7079
7078
|
var import_chalk15 = __toESM(require("chalk"));
|
|
7080
7079
|
var import_inquirer7 = __toESM(require("inquirer"));
|
|
7081
7080
|
function parseArgs() {
|
|
@@ -7174,9 +7173,9 @@ async function bindCmd() {
|
|
|
7174
7173
|
}
|
|
7175
7174
|
throw e;
|
|
7176
7175
|
}
|
|
7177
|
-
const absolutePath =
|
|
7176
|
+
const absolutePath = import_path9.default.resolve(targetPath);
|
|
7178
7177
|
console.log(import_chalk15.default.blue(`Uploading: ${absolutePath}`));
|
|
7179
|
-
const up = await uploadPath(absolutePath);
|
|
7178
|
+
const up = await uploadPath(absolutePath, { uid: authConfig.address });
|
|
7180
7179
|
if (!(up == null ? void 0 : up.contentHash)) {
|
|
7181
7180
|
console.log(import_chalk15.default.red("Upload failed, binding aborted."));
|
|
7182
7181
|
return;
|
|
@@ -7251,19 +7250,19 @@ Login failed: ${(e == null ? void 0 : e.message) || e}`));
|
|
|
7251
7250
|
|
|
7252
7251
|
// bin/create.ts
|
|
7253
7252
|
var import_chalk19 = __toESM(require("chalk"));
|
|
7254
|
-
var
|
|
7255
|
-
var
|
|
7253
|
+
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
7254
|
+
var import_path11 = __toESM(require("path"));
|
|
7256
7255
|
var import_inquirer8 = __toESM(require("inquirer"));
|
|
7257
7256
|
var import_child_process3 = require("child_process");
|
|
7258
7257
|
|
|
7259
7258
|
// bin/utils/installProjectDependencies.ts
|
|
7260
|
-
var
|
|
7261
|
-
var
|
|
7262
|
-
var
|
|
7259
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
7260
|
+
var import_os4 = __toESM(require("os"));
|
|
7261
|
+
var import_path10 = __toESM(require("path"));
|
|
7263
7262
|
var import_chalk17 = __toESM(require("chalk"));
|
|
7264
7263
|
var import_child_process2 = require("child_process");
|
|
7265
7264
|
function makeTempCacheDir() {
|
|
7266
|
-
return
|
|
7265
|
+
return import_fs_extra5.default.mkdtempSync(import_path10.default.join(import_os4.default.tmpdir(), "pinme-npm-cache-"));
|
|
7267
7266
|
}
|
|
7268
7267
|
function runInstall(cwd, cacheDir) {
|
|
7269
7268
|
(0, import_child_process2.execFileSync)("npm", ["install", "--cache", cacheDir, "--no-audit", "--no-fund"], {
|
|
@@ -7290,7 +7289,7 @@ function installProjectDependencies(cwd) {
|
|
|
7290
7289
|
} catch (error) {
|
|
7291
7290
|
lastError = error;
|
|
7292
7291
|
} finally {
|
|
7293
|
-
|
|
7292
|
+
import_fs_extra5.default.removeSync(cacheDir);
|
|
7294
7293
|
}
|
|
7295
7294
|
}
|
|
7296
7295
|
throw lastError;
|
|
@@ -7473,7 +7472,7 @@ ${configExport}
|
|
|
7473
7472
|
`;
|
|
7474
7473
|
}
|
|
7475
7474
|
function resolveExtractedTemplateDir(extractDir) {
|
|
7476
|
-
const entries =
|
|
7475
|
+
const entries = import_fs_extra6.default.readdirSync(extractDir, { withFileTypes: true });
|
|
7477
7476
|
const templateDir = entries.find((entry) => entry.isDirectory() && entry.name.startsWith(`${TEMPLATE_REPO_NAME}-`));
|
|
7478
7477
|
if (!templateDir) {
|
|
7479
7478
|
throw createConfigError("Downloaded template archive structure is invalid.", [
|
|
@@ -7481,10 +7480,10 @@ function resolveExtractedTemplateDir(extractDir) {
|
|
|
7481
7480
|
`Template branch: ${TEMPLATE_BRANCH}`
|
|
7482
7481
|
]);
|
|
7483
7482
|
}
|
|
7484
|
-
return
|
|
7483
|
+
return import_path11.default.join(extractDir, templateDir.name);
|
|
7485
7484
|
}
|
|
7486
7485
|
function updateFrontendUrlInConfig(configPath, frontendUrl) {
|
|
7487
|
-
let config =
|
|
7486
|
+
let config = import_fs_extra6.default.readFileSync(configPath, "utf-8");
|
|
7488
7487
|
if (config.includes("frontend_url")) {
|
|
7489
7488
|
config = config.replace(
|
|
7490
7489
|
/frontend_url\s*=\s*"[^"]*"/,
|
|
@@ -7497,7 +7496,7 @@ function updateFrontendUrlInConfig(configPath, frontendUrl) {
|
|
|
7497
7496
|
`
|
|
7498
7497
|
);
|
|
7499
7498
|
}
|
|
7500
|
-
|
|
7499
|
+
import_fs_extra6.default.writeFileSync(configPath, config);
|
|
7501
7500
|
}
|
|
7502
7501
|
async function createCmd(options) {
|
|
7503
7502
|
var _a2, _b;
|
|
@@ -7527,8 +7526,8 @@ async function createCmd(options) {
|
|
|
7527
7526
|
]);
|
|
7528
7527
|
projectName = answers.projectName;
|
|
7529
7528
|
}
|
|
7530
|
-
const targetDir =
|
|
7531
|
-
if (
|
|
7529
|
+
const targetDir = import_path11.default.join(PROJECT_DIR, projectName);
|
|
7530
|
+
if (import_fs_extra6.default.existsSync(targetDir) && !options.force) {
|
|
7532
7531
|
console.log(import_chalk19.default.yellow(`
|
|
7533
7532
|
Directory "${projectName}" already exists.`));
|
|
7534
7533
|
const answers = await import_inquirer8.default.prompt([
|
|
@@ -7543,7 +7542,7 @@ Directory "${projectName}" already exists.`));
|
|
|
7543
7542
|
console.log(import_chalk19.default.gray("Cancelled."));
|
|
7544
7543
|
process.exit(0);
|
|
7545
7544
|
}
|
|
7546
|
-
|
|
7545
|
+
import_fs_extra6.default.removeSync(targetDir);
|
|
7547
7546
|
}
|
|
7548
7547
|
console.log(import_chalk19.default.blue("\n1. Creating worker and database..."));
|
|
7549
7548
|
const apiUrl = getPinmeApiUrl("/create_worker");
|
|
@@ -7578,8 +7577,8 @@ Directory "${projectName}" already exists.`));
|
|
|
7578
7577
|
]);
|
|
7579
7578
|
}
|
|
7580
7579
|
console.log(import_chalk19.default.blue("\n2. Downloading template from repository..."));
|
|
7581
|
-
const zipPath =
|
|
7582
|
-
const extractDir =
|
|
7580
|
+
const zipPath = import_path11.default.join(PROJECT_DIR, "template.zip");
|
|
7581
|
+
const extractDir = import_path11.default.join(PROJECT_DIR, `.pinme-template-${Date.now()}`);
|
|
7583
7582
|
const templateZipUrl = getTemplateZipUrl(TEMPLATE_BRANCH);
|
|
7584
7583
|
let downloadSuccess = false;
|
|
7585
7584
|
console.log(import_chalk19.default.gray(` Template branch: ${TEMPLATE_BRANCH}`));
|
|
@@ -7589,14 +7588,14 @@ Directory "${projectName}" already exists.`));
|
|
|
7589
7588
|
(0, import_child_process3.execSync)(`curl -L --retry 3 --retry-delay 2 -o "${zipPath}" "${templateZipUrl}"`, {
|
|
7590
7589
|
stdio: "inherit"
|
|
7591
7590
|
});
|
|
7592
|
-
if (!
|
|
7591
|
+
if (!import_fs_extra6.default.existsSync(zipPath) || import_fs_extra6.default.statSync(zipPath).size < 100) {
|
|
7593
7592
|
throw new Error("Downloaded file is too small or empty");
|
|
7594
7593
|
}
|
|
7595
7594
|
downloadSuccess = true;
|
|
7596
7595
|
} catch (downloadError) {
|
|
7597
7596
|
console.log(import_chalk19.default.yellow(` Attempt ${attempt} failed: ${downloadError.message}`));
|
|
7598
|
-
if (
|
|
7599
|
-
|
|
7597
|
+
if (import_fs_extra6.default.existsSync(zipPath)) {
|
|
7598
|
+
import_fs_extra6.default.removeSync(zipPath);
|
|
7600
7599
|
}
|
|
7601
7600
|
if (attempt === 3) {
|
|
7602
7601
|
throw new Error(`Failed to download template after 3 attempts: ${downloadError.message}`);
|
|
@@ -7604,32 +7603,32 @@ Directory "${projectName}" already exists.`));
|
|
|
7604
7603
|
}
|
|
7605
7604
|
}
|
|
7606
7605
|
try {
|
|
7607
|
-
|
|
7606
|
+
import_fs_extra6.default.ensureDirSync(extractDir);
|
|
7608
7607
|
(0, import_child_process3.execSync)(`unzip -o "${zipPath}" -d "${extractDir}"`, {
|
|
7609
7608
|
stdio: "inherit"
|
|
7610
7609
|
});
|
|
7611
7610
|
const subDir = resolveExtractedTemplateDir(extractDir);
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
const nodeModulesPath =
|
|
7616
|
-
const packageLockPath =
|
|
7617
|
-
if (
|
|
7611
|
+
import_fs_extra6.default.copySync(subDir, targetDir);
|
|
7612
|
+
import_fs_extra6.default.removeSync(zipPath);
|
|
7613
|
+
import_fs_extra6.default.removeSync(extractDir);
|
|
7614
|
+
const nodeModulesPath = import_path11.default.join(targetDir, "node_modules");
|
|
7615
|
+
const packageLockPath = import_path11.default.join(targetDir, "package-lock.json");
|
|
7616
|
+
if (import_fs_extra6.default.existsSync(nodeModulesPath)) {
|
|
7618
7617
|
console.log(import_chalk19.default.gray(" Removing existing node_modules..."));
|
|
7619
|
-
|
|
7618
|
+
import_fs_extra6.default.removeSync(nodeModulesPath);
|
|
7620
7619
|
}
|
|
7621
|
-
if (
|
|
7620
|
+
if (import_fs_extra6.default.existsSync(packageLockPath)) {
|
|
7622
7621
|
console.log(import_chalk19.default.gray(" Removing existing package-lock.json..."));
|
|
7623
|
-
|
|
7624
|
-
}
|
|
7625
|
-
const frontendNodeModules =
|
|
7626
|
-
const backendNodeModules =
|
|
7627
|
-
const frontendPackageLock =
|
|
7628
|
-
const backendPackageLock =
|
|
7629
|
-
if (
|
|
7630
|
-
if (
|
|
7631
|
-
if (
|
|
7632
|
-
if (
|
|
7622
|
+
import_fs_extra6.default.removeSync(packageLockPath);
|
|
7623
|
+
}
|
|
7624
|
+
const frontendNodeModules = import_path11.default.join(targetDir, "frontend", "node_modules");
|
|
7625
|
+
const backendNodeModules = import_path11.default.join(targetDir, "backend", "node_modules");
|
|
7626
|
+
const frontendPackageLock = import_path11.default.join(targetDir, "frontend", "package-lock.json");
|
|
7627
|
+
const backendPackageLock = import_path11.default.join(targetDir, "backend", "package-lock.json");
|
|
7628
|
+
if (import_fs_extra6.default.existsSync(frontendNodeModules)) import_fs_extra6.default.removeSync(frontendNodeModules);
|
|
7629
|
+
if (import_fs_extra6.default.existsSync(backendNodeModules)) import_fs_extra6.default.removeSync(backendNodeModules);
|
|
7630
|
+
if (import_fs_extra6.default.existsSync(frontendPackageLock)) import_fs_extra6.default.removeSync(frontendPackageLock);
|
|
7631
|
+
if (import_fs_extra6.default.existsSync(backendPackageLock)) import_fs_extra6.default.removeSync(backendPackageLock);
|
|
7633
7632
|
console.log(import_chalk19.default.green(` Template downloaded to: ${targetDir}`));
|
|
7634
7633
|
} catch (error) {
|
|
7635
7634
|
throw createCommandError("template extraction", `unzip -o "${zipPath}" -d "${PROJECT_DIR}"`, error, [
|
|
@@ -7637,58 +7636,58 @@ Directory "${projectName}" already exists.`));
|
|
|
7637
7636
|
]);
|
|
7638
7637
|
}
|
|
7639
7638
|
console.log(import_chalk19.default.blue("\n3. Updating configuration..."));
|
|
7640
|
-
const configPath =
|
|
7641
|
-
const config =
|
|
7639
|
+
const configPath = import_path11.default.join(targetDir, "pinme.toml");
|
|
7640
|
+
const config = import_fs_extra6.default.readFileSync(configPath, "utf-8");
|
|
7642
7641
|
let updatedConfig = config.replace(
|
|
7643
7642
|
/project_name = ".*"/,
|
|
7644
7643
|
`project_name = "${workerData.project_name}"`
|
|
7645
7644
|
);
|
|
7646
|
-
|
|
7645
|
+
import_fs_extra6.default.writeFileSync(configPath, updatedConfig);
|
|
7647
7646
|
console.log(import_chalk19.default.green(` Updated pinme.toml`));
|
|
7648
7647
|
console.log(import_chalk19.default.gray(` metadata: ${workerData.metadata}`));
|
|
7649
|
-
const backendDir =
|
|
7650
|
-
if (
|
|
7648
|
+
const backendDir = import_path11.default.join(targetDir, "backend");
|
|
7649
|
+
if (import_fs_extra6.default.existsSync(backendDir) && workerData.metadata) {
|
|
7651
7650
|
const metadataContent = typeof workerData.metadata === "string" ? workerData.metadata : JSON.stringify(workerData.metadata, null, 2);
|
|
7652
|
-
|
|
7653
|
-
|
|
7651
|
+
import_fs_extra6.default.writeFileSync(
|
|
7652
|
+
import_path11.default.join(backendDir, "metadata.json"),
|
|
7654
7653
|
metadataContent
|
|
7655
7654
|
);
|
|
7656
7655
|
console.log(import_chalk19.default.green(` Saved metadata.json`));
|
|
7657
7656
|
}
|
|
7658
|
-
const wranglerPath =
|
|
7659
|
-
if (
|
|
7660
|
-
let wranglerContent =
|
|
7657
|
+
const wranglerPath = import_path11.default.join(backendDir, "wrangler.toml");
|
|
7658
|
+
if (import_fs_extra6.default.existsSync(wranglerPath) && workerData.api_key) {
|
|
7659
|
+
let wranglerContent = import_fs_extra6.default.readFileSync(wranglerPath, "utf-8");
|
|
7661
7660
|
wranglerContent = wranglerContent.replace(
|
|
7662
7661
|
/^name = ".*"$/m,
|
|
7663
7662
|
`name = "${workerData.project_name}"`
|
|
7664
7663
|
);
|
|
7665
|
-
|
|
7664
|
+
import_fs_extra6.default.writeFileSync(wranglerPath, wranglerContent);
|
|
7666
7665
|
console.log(import_chalk19.default.green(` Updated backend/wrangler.toml API_KEY`));
|
|
7667
7666
|
}
|
|
7668
|
-
const frontendConfigPath =
|
|
7667
|
+
const frontendConfigPath = import_path11.default.join(targetDir, "frontend", "src", "utils", "config.ts");
|
|
7669
7668
|
if (workerData.public_client_config) {
|
|
7670
|
-
const frontendConfigContent =
|
|
7671
|
-
|
|
7672
|
-
|
|
7669
|
+
const frontendConfigContent = import_fs_extra6.default.existsSync(frontendConfigPath) ? import_fs_extra6.default.readFileSync(frontendConfigPath, "utf-8") : "";
|
|
7670
|
+
import_fs_extra6.default.ensureDirSync(import_path11.default.dirname(frontendConfigPath));
|
|
7671
|
+
import_fs_extra6.default.writeFileSync(
|
|
7673
7672
|
frontendConfigPath,
|
|
7674
7673
|
injectPublicClientConfigIntoFile(frontendConfigContent, workerData.public_client_config)
|
|
7675
7674
|
);
|
|
7676
7675
|
console.log(import_chalk19.default.green(` Updated frontend/src/utils/config.ts public_client_config`));
|
|
7677
7676
|
}
|
|
7678
|
-
const envExamplePath =
|
|
7679
|
-
const envPath =
|
|
7680
|
-
if (
|
|
7681
|
-
let envContent =
|
|
7677
|
+
const envExamplePath = import_path11.default.join(targetDir, "frontend", ".env.example");
|
|
7678
|
+
const envPath = import_path11.default.join(targetDir, "frontend", ".env");
|
|
7679
|
+
if (import_fs_extra6.default.existsSync(envExamplePath)) {
|
|
7680
|
+
let envContent = import_fs_extra6.default.readFileSync(envExamplePath, "utf-8");
|
|
7682
7681
|
envContent = envContent.replace(/your-project/g, workerData.project_name);
|
|
7683
7682
|
envContent = envContent.replace(
|
|
7684
7683
|
/^VITE_API_URL=.*$/m,
|
|
7685
7684
|
`VITE_API_URL=${workerData.api_domain}`
|
|
7686
7685
|
);
|
|
7687
|
-
|
|
7686
|
+
import_fs_extra6.default.writeFileSync(envPath, envContent);
|
|
7688
7687
|
console.log(import_chalk19.default.green(` Created frontend/.env file`));
|
|
7689
7688
|
console.log(import_chalk19.default.gray(` VITE_API_URL: ${workerData.api_domain}`));
|
|
7690
7689
|
}
|
|
7691
|
-
let pinmeConfig =
|
|
7690
|
+
let pinmeConfig = import_fs_extra6.default.readFileSync(configPath, "utf-8");
|
|
7692
7691
|
if (pinmeConfig.includes("api_url")) {
|
|
7693
7692
|
pinmeConfig = pinmeConfig.replace(
|
|
7694
7693
|
/api_url\s*=\s*"[^"]*"/,
|
|
@@ -7705,7 +7704,7 @@ Directory "${projectName}" already exists.`));
|
|
|
7705
7704
|
}
|
|
7706
7705
|
pinmeConfig = newLines.join("\n");
|
|
7707
7706
|
}
|
|
7708
|
-
|
|
7707
|
+
import_fs_extra6.default.writeFileSync(configPath, pinmeConfig);
|
|
7709
7708
|
console.log(import_chalk19.default.green(` Updated pinme.toml with api_url`));
|
|
7710
7709
|
console.log(import_chalk19.default.blue("\n4. Installing dependencies..."));
|
|
7711
7710
|
try {
|
|
@@ -7761,26 +7760,26 @@ Directory "${projectName}" already exists.`));
|
|
|
7761
7760
|
"Fix the build error shown above, then rerun `pinme create`."
|
|
7762
7761
|
]);
|
|
7763
7762
|
}
|
|
7764
|
-
const distWorkerDir =
|
|
7765
|
-
const workerJsPath =
|
|
7766
|
-
if (!
|
|
7763
|
+
const distWorkerDir = import_path11.default.join(targetDir, "dist-worker");
|
|
7764
|
+
const workerJsPath = import_path11.default.join(distWorkerDir, "worker.js");
|
|
7765
|
+
if (!import_fs_extra6.default.existsSync(distWorkerDir) || !import_fs_extra6.default.existsSync(workerJsPath)) {
|
|
7767
7766
|
throw createConfigError("Built worker output not found: `dist-worker/worker.js`.", [
|
|
7768
7767
|
"Make sure `npm run build:worker` completed successfully."
|
|
7769
7768
|
]);
|
|
7770
7769
|
}
|
|
7771
7770
|
const modulePaths = [];
|
|
7772
|
-
const files =
|
|
7771
|
+
const files = import_fs_extra6.default.readdirSync(distWorkerDir);
|
|
7773
7772
|
for (const file of files) {
|
|
7774
7773
|
if (file.endsWith(".js") && file !== "worker.js") {
|
|
7775
|
-
modulePaths.push(
|
|
7774
|
+
modulePaths.push(import_path11.default.join(distWorkerDir, file));
|
|
7776
7775
|
}
|
|
7777
7776
|
}
|
|
7778
|
-
const sqlDir =
|
|
7777
|
+
const sqlDir = import_path11.default.join(targetDir, "db");
|
|
7779
7778
|
const sqlFiles = [];
|
|
7780
|
-
if (
|
|
7781
|
-
const sqlFileNames =
|
|
7779
|
+
if (import_fs_extra6.default.existsSync(sqlDir)) {
|
|
7780
|
+
const sqlFileNames = import_fs_extra6.default.readdirSync(sqlDir).filter((f) => f.endsWith(".sql")).sort();
|
|
7782
7781
|
for (const filename of sqlFileNames) {
|
|
7783
|
-
sqlFiles.push(
|
|
7782
|
+
sqlFiles.push(import_path11.default.join(sqlDir, filename));
|
|
7784
7783
|
console.log(import_chalk19.default.gray(` Including SQL: ${filename}`));
|
|
7785
7784
|
}
|
|
7786
7785
|
}
|
|
@@ -7795,20 +7794,20 @@ Directory "${projectName}" already exists.`));
|
|
|
7795
7794
|
formData.append("metadata", new Blob2([metadataContent], {
|
|
7796
7795
|
type: "application/json"
|
|
7797
7796
|
}), "metadata.json");
|
|
7798
|
-
const workerCode =
|
|
7797
|
+
const workerCode = import_fs_extra6.default.readFileSync(workerJsPath, "utf-8");
|
|
7799
7798
|
formData.append("worker.js", new Blob2([workerCode], {
|
|
7800
7799
|
type: "application/javascript+module"
|
|
7801
7800
|
}), "worker.js");
|
|
7802
7801
|
for (const modulePath of modulePaths) {
|
|
7803
|
-
const filename =
|
|
7804
|
-
const content =
|
|
7802
|
+
const filename = import_path11.default.basename(modulePath);
|
|
7803
|
+
const content = import_fs_extra6.default.readFileSync(modulePath, "utf-8");
|
|
7805
7804
|
formData.append(filename, new Blob2([content], {
|
|
7806
7805
|
type: "application/javascript+module"
|
|
7807
7806
|
}), filename);
|
|
7808
7807
|
}
|
|
7809
7808
|
for (const sqlFile of sqlFiles) {
|
|
7810
|
-
const filename =
|
|
7811
|
-
const content =
|
|
7809
|
+
const filename = import_path11.default.basename(sqlFile);
|
|
7810
|
+
const content = import_fs_extra6.default.readFileSync(sqlFile, "utf-8");
|
|
7812
7811
|
formData.append("sql_file", new Blob2([content], {
|
|
7813
7812
|
type: "application/sql"
|
|
7814
7813
|
}), filename);
|
|
@@ -7841,8 +7840,8 @@ Directory "${projectName}" already exists.`));
|
|
|
7841
7840
|
]);
|
|
7842
7841
|
}
|
|
7843
7842
|
console.log(import_chalk19.default.blue("\n7. Building frontend..."));
|
|
7844
|
-
const frontendDir =
|
|
7845
|
-
if (
|
|
7843
|
+
const frontendDir = import_path11.default.join(targetDir, "frontend");
|
|
7844
|
+
if (import_fs_extra6.default.existsSync(frontendDir)) {
|
|
7846
7845
|
try {
|
|
7847
7846
|
(0, import_child_process3.execSync)("npm run build:frontend", {
|
|
7848
7847
|
cwd: targetDir,
|
|
@@ -7856,12 +7855,13 @@ Directory "${projectName}" already exists.`));
|
|
|
7856
7855
|
}
|
|
7857
7856
|
console.log(import_chalk19.default.blue(" Uploading to IPFS..."));
|
|
7858
7857
|
try {
|
|
7859
|
-
const uploadResult = await uploadPath(
|
|
7860
|
-
projectName: workerData.project_name
|
|
7858
|
+
const uploadResult = await uploadPath(import_path11.default.join(frontendDir, "dist"), {
|
|
7859
|
+
projectName: workerData.project_name,
|
|
7860
|
+
uid: headers["token-address"]
|
|
7861
7861
|
});
|
|
7862
7862
|
console.log(import_chalk19.default.green(` Frontend uploaded to IPFS: ${uploadResult.publicUrl}`));
|
|
7863
7863
|
updateFrontendUrlInConfig(
|
|
7864
|
-
|
|
7864
|
+
import_path11.default.join(targetDir, "pinme.toml"),
|
|
7865
7865
|
uploadResult.publicUrl
|
|
7866
7866
|
);
|
|
7867
7867
|
console.log(import_chalk19.default.green(" Updated pinme.toml with frontend URL"));
|
|
@@ -7887,31 +7887,31 @@ Next steps:`));
|
|
|
7887
7887
|
|
|
7888
7888
|
// bin/save.ts
|
|
7889
7889
|
var import_chalk20 = __toESM(require("chalk"));
|
|
7890
|
-
var
|
|
7891
|
-
var
|
|
7890
|
+
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
7891
|
+
var import_path12 = __toESM(require("path"));
|
|
7892
7892
|
var import_child_process4 = require("child_process");
|
|
7893
7893
|
var PROJECT_DIR2 = process.cwd();
|
|
7894
7894
|
function loadConfig() {
|
|
7895
|
-
const configPath =
|
|
7896
|
-
if (!
|
|
7895
|
+
const configPath = import_path12.default.join(PROJECT_DIR2, "pinme.toml");
|
|
7896
|
+
if (!import_fs_extra7.default.existsSync(configPath)) {
|
|
7897
7897
|
throw createConfigError("`pinme.toml` not found in the current directory.", [
|
|
7898
7898
|
"Run this command from the Pinme project root.",
|
|
7899
7899
|
"If the project has not been initialized yet, create or restore `pinme.toml` first."
|
|
7900
7900
|
]);
|
|
7901
7901
|
}
|
|
7902
|
-
const configContent =
|
|
7902
|
+
const configContent = import_fs_extra7.default.readFileSync(configPath, "utf-8");
|
|
7903
7903
|
const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
|
|
7904
7904
|
return {
|
|
7905
7905
|
project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
|
|
7906
7906
|
};
|
|
7907
7907
|
}
|
|
7908
7908
|
function getMetadata() {
|
|
7909
|
-
const metadataPath =
|
|
7910
|
-
if (!
|
|
7909
|
+
const metadataPath = import_path12.default.join(PROJECT_DIR2, "backend", "metadata.json");
|
|
7910
|
+
if (!import_fs_extra7.default.existsSync(metadataPath)) {
|
|
7911
7911
|
console.log(import_chalk20.default.yellow(" Warning: metadata.json not found, using empty metadata"));
|
|
7912
7912
|
return {};
|
|
7913
7913
|
}
|
|
7914
|
-
return
|
|
7914
|
+
return import_fs_extra7.default.readJsonSync(metadataPath);
|
|
7915
7915
|
}
|
|
7916
7916
|
function buildWorker() {
|
|
7917
7917
|
console.log(import_chalk20.default.blue("Building worker..."));
|
|
@@ -7972,34 +7972,34 @@ function installDependencies() {
|
|
|
7972
7972
|
}
|
|
7973
7973
|
}
|
|
7974
7974
|
function getBuiltWorker() {
|
|
7975
|
-
const distWorkerDir =
|
|
7976
|
-
if (!
|
|
7975
|
+
const distWorkerDir = import_path12.default.join(PROJECT_DIR2, "dist-worker");
|
|
7976
|
+
if (!import_fs_extra7.default.existsSync(distWorkerDir)) {
|
|
7977
7977
|
throw createConfigError("Built worker output not found: `dist-worker/`.", [
|
|
7978
7978
|
"Make sure `npm run build:worker` completed successfully."
|
|
7979
7979
|
]);
|
|
7980
7980
|
}
|
|
7981
|
-
const workerJsPath =
|
|
7982
|
-
if (!
|
|
7981
|
+
const workerJsPath = import_path12.default.join(distWorkerDir, "worker.js");
|
|
7982
|
+
if (!import_fs_extra7.default.existsSync(workerJsPath)) {
|
|
7983
7983
|
throw createConfigError("Built worker entry file not found: `dist-worker/worker.js`.", [
|
|
7984
7984
|
"Check the worker build output and bundler config."
|
|
7985
7985
|
]);
|
|
7986
7986
|
}
|
|
7987
7987
|
const modulePaths = [];
|
|
7988
|
-
const files =
|
|
7988
|
+
const files = import_fs_extra7.default.readdirSync(distWorkerDir);
|
|
7989
7989
|
for (const file of files) {
|
|
7990
7990
|
if (file.endsWith(".js") && file !== "worker.js") {
|
|
7991
|
-
modulePaths.push(
|
|
7991
|
+
modulePaths.push(import_path12.default.join(distWorkerDir, file));
|
|
7992
7992
|
}
|
|
7993
7993
|
}
|
|
7994
7994
|
return { workerJsPath, modulePaths };
|
|
7995
7995
|
}
|
|
7996
7996
|
function getSqlFiles() {
|
|
7997
|
-
const sqlDir =
|
|
7998
|
-
if (!
|
|
7997
|
+
const sqlDir = import_path12.default.join(PROJECT_DIR2, "db");
|
|
7998
|
+
if (!import_fs_extra7.default.existsSync(sqlDir)) {
|
|
7999
7999
|
return [];
|
|
8000
8000
|
}
|
|
8001
|
-
const files =
|
|
8002
|
-
return files.map((f) =>
|
|
8001
|
+
const files = import_fs_extra7.default.readdirSync(sqlDir).filter((f) => f.endsWith(".sql")).sort();
|
|
8002
|
+
return files.map((f) => import_path12.default.join(sqlDir, f));
|
|
8003
8003
|
}
|
|
8004
8004
|
async function saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, projectName) {
|
|
8005
8005
|
var _a2, _b;
|
|
@@ -8019,20 +8019,20 @@ async function saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, project
|
|
|
8019
8019
|
formData.append("metadata", new Blob2([JSON.stringify(metadata)], {
|
|
8020
8020
|
type: "application/json"
|
|
8021
8021
|
}), "metadata.json");
|
|
8022
|
-
const workerCode =
|
|
8022
|
+
const workerCode = import_fs_extra7.default.readFileSync(workerJsPath, "utf-8");
|
|
8023
8023
|
formData.append("worker.js", new Blob2([workerCode], {
|
|
8024
8024
|
type: "application/javascript+module"
|
|
8025
8025
|
}), "worker.js");
|
|
8026
8026
|
for (const modulePath of modulePaths) {
|
|
8027
|
-
const filename =
|
|
8028
|
-
const content =
|
|
8027
|
+
const filename = import_path12.default.basename(modulePath);
|
|
8028
|
+
const content = import_fs_extra7.default.readFileSync(modulePath, "utf-8");
|
|
8029
8029
|
formData.append(filename, new Blob2([content], {
|
|
8030
8030
|
type: "application/javascript+module"
|
|
8031
8031
|
}), filename);
|
|
8032
8032
|
}
|
|
8033
8033
|
for (const sqlFile of sqlFiles) {
|
|
8034
|
-
const filename =
|
|
8035
|
-
const content =
|
|
8034
|
+
const filename = import_path12.default.basename(sqlFile);
|
|
8035
|
+
const content = import_fs_extra7.default.readFileSync(sqlFile, "utf-8");
|
|
8036
8036
|
formData.append("sql_file", new Blob2([content], {
|
|
8037
8037
|
type: "application/sql"
|
|
8038
8038
|
}), filename);
|
|
@@ -8082,7 +8082,7 @@ function buildFrontend() {
|
|
|
8082
8082
|
}
|
|
8083
8083
|
}
|
|
8084
8084
|
function updateFrontendUrlInConfig2(configPath, frontendUrl) {
|
|
8085
|
-
let config =
|
|
8085
|
+
let config = import_fs_extra7.default.readFileSync(configPath, "utf-8");
|
|
8086
8086
|
if (config.includes("frontend_url")) {
|
|
8087
8087
|
config = config.replace(
|
|
8088
8088
|
/frontend_url\s*=\s*"[^"]*"/,
|
|
@@ -8095,16 +8095,18 @@ function updateFrontendUrlInConfig2(configPath, frontendUrl) {
|
|
|
8095
8095
|
`
|
|
8096
8096
|
);
|
|
8097
8097
|
}
|
|
8098
|
-
|
|
8098
|
+
import_fs_extra7.default.writeFileSync(configPath, config);
|
|
8099
8099
|
}
|
|
8100
8100
|
async function deployFrontend(projectName) {
|
|
8101
8101
|
console.log(import_chalk20.default.blue("Deploying frontend to IPFS..."));
|
|
8102
8102
|
try {
|
|
8103
|
-
const
|
|
8104
|
-
|
|
8103
|
+
const headers = getAuthHeaders();
|
|
8104
|
+
const uploadResult = await uploadPath(import_path12.default.join(PROJECT_DIR2, "frontend", "dist"), {
|
|
8105
|
+
projectName,
|
|
8106
|
+
uid: headers["token-address"]
|
|
8105
8107
|
});
|
|
8106
8108
|
console.log(import_chalk20.default.green(`Frontend deployed to IPFS: ${uploadResult.publicUrl}`));
|
|
8107
|
-
updateFrontendUrlInConfig2(
|
|
8109
|
+
updateFrontendUrlInConfig2(import_path12.default.join(PROJECT_DIR2, "pinme.toml"), uploadResult.publicUrl);
|
|
8108
8110
|
console.log(import_chalk20.default.green("Updated pinme.toml with frontend URL"));
|
|
8109
8111
|
} catch (error) {
|
|
8110
8112
|
throw createCommandError("frontend deploy", "upload frontend/dist", error, [
|
|
@@ -8120,11 +8122,11 @@ async function saveCmd(options) {
|
|
|
8120
8122
|
"Run `pinme login` and retry."
|
|
8121
8123
|
]);
|
|
8122
8124
|
}
|
|
8123
|
-
const projectDir = options.projectName || options.name ?
|
|
8124
|
-
const tokenFileSrc =
|
|
8125
|
-
const tokenFileDst =
|
|
8126
|
-
if (
|
|
8127
|
-
|
|
8125
|
+
const projectDir = options.projectName || options.name ? import_path12.default.join(PROJECT_DIR2, options.projectName || options.name) : PROJECT_DIR2;
|
|
8126
|
+
const tokenFileSrc = import_path12.default.join(PROJECT_DIR2, ".token.json");
|
|
8127
|
+
const tokenFileDst = import_path12.default.join(projectDir, ".token.json");
|
|
8128
|
+
if (import_fs_extra7.default.existsSync(tokenFileSrc) && !import_fs_extra7.default.existsSync(tokenFileDst)) {
|
|
8129
|
+
import_fs_extra7.default.copySync(tokenFileSrc, tokenFileDst);
|
|
8128
8130
|
}
|
|
8129
8131
|
console.log(import_chalk20.default.blue("Deploying to platform...\n"));
|
|
8130
8132
|
console.log(import_chalk20.default.gray(`Project dir: ${PROJECT_DIR2}`));
|
|
@@ -8161,36 +8163,36 @@ async function saveCmd(options) {
|
|
|
8161
8163
|
|
|
8162
8164
|
// bin/updateDb.ts
|
|
8163
8165
|
var import_chalk21 = __toESM(require("chalk"));
|
|
8164
|
-
var
|
|
8165
|
-
var
|
|
8166
|
+
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
8167
|
+
var import_path13 = __toESM(require("path"));
|
|
8166
8168
|
var PROJECT_DIR3 = process.cwd();
|
|
8167
8169
|
function loadConfig2() {
|
|
8168
|
-
const configPath =
|
|
8169
|
-
if (!
|
|
8170
|
+
const configPath = import_path13.default.join(PROJECT_DIR3, "pinme.toml");
|
|
8171
|
+
if (!import_fs_extra8.default.existsSync(configPath)) {
|
|
8170
8172
|
throw createConfigError("`pinme.toml` not found in the current directory.", [
|
|
8171
8173
|
"Run this command from the Pinme project root."
|
|
8172
8174
|
]);
|
|
8173
8175
|
}
|
|
8174
|
-
const configContent =
|
|
8176
|
+
const configContent = import_fs_extra8.default.readFileSync(configPath, "utf-8");
|
|
8175
8177
|
const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
|
|
8176
8178
|
return {
|
|
8177
8179
|
project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
|
|
8178
8180
|
};
|
|
8179
8181
|
}
|
|
8180
8182
|
function getSqlFiles2() {
|
|
8181
|
-
const sqlDir =
|
|
8182
|
-
if (!
|
|
8183
|
+
const sqlDir = import_path13.default.join(PROJECT_DIR3, "db");
|
|
8184
|
+
if (!import_fs_extra8.default.existsSync(sqlDir)) {
|
|
8183
8185
|
throw createConfigError("SQL directory not found: `db/`.", [
|
|
8184
8186
|
"Create a `db/` directory and add at least one `.sql` migration file."
|
|
8185
8187
|
]);
|
|
8186
8188
|
}
|
|
8187
|
-
const files =
|
|
8189
|
+
const files = import_fs_extra8.default.readdirSync(sqlDir).filter((f) => f.endsWith(".sql")).sort();
|
|
8188
8190
|
if (files.length === 0) {
|
|
8189
8191
|
throw createConfigError("No `.sql` files were found in `db/`.", [
|
|
8190
8192
|
"Add one or more migration files before running `pinme update-db`."
|
|
8191
8193
|
]);
|
|
8192
8194
|
}
|
|
8193
|
-
return files.map((f) =>
|
|
8195
|
+
return files.map((f) => import_path13.default.join(sqlDir, f));
|
|
8194
8196
|
}
|
|
8195
8197
|
async function updateDb(sqlFiles, projectName) {
|
|
8196
8198
|
console.log(import_chalk21.default.blue("Importing SQL files to database..."));
|
|
@@ -8205,8 +8207,8 @@ async function updateDb(sqlFiles, projectName) {
|
|
|
8205
8207
|
const formData = new FormData4();
|
|
8206
8208
|
let totalSize = 0;
|
|
8207
8209
|
for (const sqlFile of sqlFiles) {
|
|
8208
|
-
const filename =
|
|
8209
|
-
const content =
|
|
8210
|
+
const filename = import_path13.default.basename(sqlFile);
|
|
8211
|
+
const content = import_fs_extra8.default.readFileSync(sqlFile);
|
|
8210
8212
|
totalSize += content.length;
|
|
8211
8213
|
if (totalSize > 10 * 1024 * 1024) {
|
|
8212
8214
|
throw createConfigError("Total SQL payload exceeds the 10MB platform limit.", [
|
|
@@ -8261,11 +8263,11 @@ async function updateDbCmd(options) {
|
|
|
8261
8263
|
"Run `pinme login` and retry."
|
|
8262
8264
|
]);
|
|
8263
8265
|
}
|
|
8264
|
-
const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ?
|
|
8265
|
-
const tokenFileSrc =
|
|
8266
|
-
const tokenFileDst =
|
|
8267
|
-
if (
|
|
8268
|
-
|
|
8266
|
+
const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ? import_path13.default.join(PROJECT_DIR3, options.projectName || options.name) : PROJECT_DIR3;
|
|
8267
|
+
const tokenFileSrc = import_path13.default.join(PROJECT_DIR3, ".token.json");
|
|
8268
|
+
const tokenFileDst = import_path13.default.join(projectDir, ".token.json");
|
|
8269
|
+
if (import_fs_extra8.default.existsSync(tokenFileSrc) && !import_fs_extra8.default.existsSync(tokenFileDst)) {
|
|
8270
|
+
import_fs_extra8.default.copySync(tokenFileSrc, tokenFileDst);
|
|
8269
8271
|
}
|
|
8270
8272
|
console.log(import_chalk21.default.blue("Importing SQL to database...\n"));
|
|
8271
8273
|
console.log(import_chalk21.default.gray(`Project dir: ${PROJECT_DIR3}`));
|
|
@@ -8290,31 +8292,31 @@ async function updateDbCmd(options) {
|
|
|
8290
8292
|
|
|
8291
8293
|
// bin/updateWorker.ts
|
|
8292
8294
|
var import_chalk22 = __toESM(require("chalk"));
|
|
8293
|
-
var
|
|
8294
|
-
var
|
|
8295
|
+
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
8296
|
+
var import_path14 = __toESM(require("path"));
|
|
8295
8297
|
var import_child_process5 = require("child_process");
|
|
8296
8298
|
var PROJECT_DIR4 = process.cwd();
|
|
8297
8299
|
function loadConfig3() {
|
|
8298
|
-
const configPath =
|
|
8299
|
-
if (!
|
|
8300
|
+
const configPath = import_path14.default.join(PROJECT_DIR4, "pinme.toml");
|
|
8301
|
+
if (!import_fs_extra9.default.existsSync(configPath)) {
|
|
8300
8302
|
throw createConfigError("`pinme.toml` not found in the current directory.", [
|
|
8301
8303
|
"Run this command from the Pinme project root."
|
|
8302
8304
|
]);
|
|
8303
8305
|
}
|
|
8304
|
-
const configContent =
|
|
8306
|
+
const configContent = import_fs_extra9.default.readFileSync(configPath, "utf-8");
|
|
8305
8307
|
const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
|
|
8306
8308
|
return {
|
|
8307
8309
|
project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
|
|
8308
8310
|
};
|
|
8309
8311
|
}
|
|
8310
8312
|
function getMetadata2() {
|
|
8311
|
-
const metadataPath =
|
|
8312
|
-
if (!
|
|
8313
|
+
const metadataPath = import_path14.default.join(PROJECT_DIR4, "backend", "metadata.json");
|
|
8314
|
+
if (!import_fs_extra9.default.existsSync(metadataPath)) {
|
|
8313
8315
|
throw createConfigError("`backend/metadata.json` not found.", [
|
|
8314
8316
|
"Create `backend/metadata.json` or restore it from the project template."
|
|
8315
8317
|
]);
|
|
8316
8318
|
}
|
|
8317
|
-
return
|
|
8319
|
+
return import_fs_extra9.default.readJsonSync(metadataPath);
|
|
8318
8320
|
}
|
|
8319
8321
|
function buildWorker2() {
|
|
8320
8322
|
console.log(import_chalk22.default.blue("Building worker..."));
|
|
@@ -8331,23 +8333,23 @@ function buildWorker2() {
|
|
|
8331
8333
|
}
|
|
8332
8334
|
}
|
|
8333
8335
|
function getBuiltWorker2() {
|
|
8334
|
-
const distWorkerDir =
|
|
8335
|
-
if (!
|
|
8336
|
+
const distWorkerDir = import_path14.default.join(PROJECT_DIR4, "dist-worker");
|
|
8337
|
+
if (!import_fs_extra9.default.existsSync(distWorkerDir)) {
|
|
8336
8338
|
throw createConfigError("Built worker output not found: `dist-worker/`.", [
|
|
8337
8339
|
"Make sure `npm run build:worker` completed successfully."
|
|
8338
8340
|
]);
|
|
8339
8341
|
}
|
|
8340
|
-
const workerJsPath =
|
|
8341
|
-
if (!
|
|
8342
|
+
const workerJsPath = import_path14.default.join(distWorkerDir, "worker.js");
|
|
8343
|
+
if (!import_fs_extra9.default.existsSync(workerJsPath)) {
|
|
8342
8344
|
throw createConfigError("Built worker entry file not found: `dist-worker/worker.js`.", [
|
|
8343
8345
|
"Check the worker build output and bundler config."
|
|
8344
8346
|
]);
|
|
8345
8347
|
}
|
|
8346
8348
|
const modulePaths = [];
|
|
8347
|
-
const files =
|
|
8349
|
+
const files = import_fs_extra9.default.readdirSync(distWorkerDir);
|
|
8348
8350
|
for (const file of files) {
|
|
8349
8351
|
if (file.endsWith(".js") && file !== "worker.js") {
|
|
8350
|
-
modulePaths.push(
|
|
8352
|
+
modulePaths.push(import_path14.default.join(distWorkerDir, file));
|
|
8351
8353
|
}
|
|
8352
8354
|
}
|
|
8353
8355
|
return { workerJsPath, modulePaths };
|
|
@@ -8368,13 +8370,13 @@ async function updateWorker(workerJsPath, modulePaths, metadata, projectName) {
|
|
|
8368
8370
|
formData.append("metadata", new Blob2([JSON.stringify(metadata)], {
|
|
8369
8371
|
type: "application/json"
|
|
8370
8372
|
}), "metadata.json");
|
|
8371
|
-
const workerCode =
|
|
8373
|
+
const workerCode = import_fs_extra9.default.readFileSync(workerJsPath, "utf-8");
|
|
8372
8374
|
formData.append("worker.js", new Blob2([workerCode], {
|
|
8373
8375
|
type: "application/javascript+module"
|
|
8374
8376
|
}), "worker.js");
|
|
8375
8377
|
for (const modulePath of modulePaths) {
|
|
8376
|
-
const filename =
|
|
8377
|
-
const content =
|
|
8378
|
+
const filename = import_path14.default.basename(modulePath);
|
|
8379
|
+
const content = import_fs_extra9.default.readFileSync(modulePath, "utf-8");
|
|
8378
8380
|
formData.append(filename, new Blob2([content], {
|
|
8379
8381
|
type: "application/javascript+module"
|
|
8380
8382
|
}), filename);
|
|
@@ -8436,11 +8438,11 @@ async function updateWorkerCmd(options) {
|
|
|
8436
8438
|
"Run `pinme login` and retry."
|
|
8437
8439
|
]);
|
|
8438
8440
|
}
|
|
8439
|
-
const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ?
|
|
8440
|
-
const tokenFileSrc =
|
|
8441
|
-
const tokenFileDst =
|
|
8442
|
-
if (
|
|
8443
|
-
|
|
8441
|
+
const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ? import_path14.default.join(PROJECT_DIR4, options.projectName || options.name) : PROJECT_DIR4;
|
|
8442
|
+
const tokenFileSrc = import_path14.default.join(PROJECT_DIR4, ".token.json");
|
|
8443
|
+
const tokenFileDst = import_path14.default.join(projectDir, ".token.json");
|
|
8444
|
+
if (import_fs_extra9.default.existsSync(tokenFileSrc) && !import_fs_extra9.default.existsSync(tokenFileDst)) {
|
|
8445
|
+
import_fs_extra9.default.copySync(tokenFileSrc, tokenFileDst);
|
|
8444
8446
|
}
|
|
8445
8447
|
console.log(import_chalk22.default.blue("Updating worker...\n"));
|
|
8446
8448
|
console.log(import_chalk22.default.gray(`Project dir: ${PROJECT_DIR4}`));
|
|
@@ -8470,18 +8472,18 @@ async function updateWorkerCmd(options) {
|
|
|
8470
8472
|
|
|
8471
8473
|
// bin/updateWeb.ts
|
|
8472
8474
|
var import_chalk23 = __toESM(require("chalk"));
|
|
8473
|
-
var
|
|
8474
|
-
var
|
|
8475
|
+
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
8476
|
+
var import_path15 = __toESM(require("path"));
|
|
8475
8477
|
var import_child_process6 = require("child_process");
|
|
8476
8478
|
var PROJECT_DIR5 = process.cwd();
|
|
8477
8479
|
function loadConfig4() {
|
|
8478
|
-
const configPath =
|
|
8479
|
-
if (!
|
|
8480
|
+
const configPath = import_path15.default.join(PROJECT_DIR5, "pinme.toml");
|
|
8481
|
+
if (!import_fs_extra10.default.existsSync(configPath)) {
|
|
8480
8482
|
throw createConfigError("`pinme.toml` not found in the current directory.", [
|
|
8481
8483
|
"Run this command from the Pinme project root."
|
|
8482
8484
|
]);
|
|
8483
8485
|
}
|
|
8484
|
-
const configContent =
|
|
8486
|
+
const configContent = import_fs_extra10.default.readFileSync(configPath, "utf-8");
|
|
8485
8487
|
const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
|
|
8486
8488
|
return {
|
|
8487
8489
|
project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
|
|
@@ -8504,8 +8506,10 @@ function buildFrontend2() {
|
|
|
8504
8506
|
async function deployFrontend2(projectName) {
|
|
8505
8507
|
console.log(import_chalk23.default.blue("Deploying frontend to IPFS..."));
|
|
8506
8508
|
try {
|
|
8507
|
-
const
|
|
8508
|
-
|
|
8509
|
+
const headers = getAuthHeaders();
|
|
8510
|
+
const uploadResult = await uploadPath(import_path15.default.join(PROJECT_DIR5, "frontend", "dist"), {
|
|
8511
|
+
projectName,
|
|
8512
|
+
uid: headers["token-address"]
|
|
8509
8513
|
});
|
|
8510
8514
|
console.log(import_chalk23.default.green(`Frontend deployed to IPFS: ${uploadResult.publicUrl}`));
|
|
8511
8515
|
} catch (error) {
|
|
@@ -8522,11 +8526,11 @@ async function updateWebCmd(options) {
|
|
|
8522
8526
|
"Run `pinme login` and retry."
|
|
8523
8527
|
]);
|
|
8524
8528
|
}
|
|
8525
|
-
const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ?
|
|
8526
|
-
const tokenFileSrc =
|
|
8527
|
-
const tokenFileDst =
|
|
8528
|
-
if (
|
|
8529
|
-
|
|
8529
|
+
const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ? import_path15.default.join(PROJECT_DIR5, options.projectName || options.name) : PROJECT_DIR5;
|
|
8530
|
+
const tokenFileSrc = import_path15.default.join(PROJECT_DIR5, ".token.json");
|
|
8531
|
+
const tokenFileDst = import_path15.default.join(projectDir, ".token.json");
|
|
8532
|
+
if (import_fs_extra10.default.existsSync(tokenFileSrc) && !import_fs_extra10.default.existsSync(tokenFileDst)) {
|
|
8533
|
+
import_fs_extra10.default.copySync(tokenFileSrc, tokenFileDst);
|
|
8530
8534
|
}
|
|
8531
8535
|
console.log(import_chalk23.default.blue("Updating web (frontend)...\n"));
|
|
8532
8536
|
console.log(import_chalk23.default.gray(`Project dir: ${PROJECT_DIR5}`));
|
|
@@ -8552,14 +8556,14 @@ async function updateWebCmd(options) {
|
|
|
8552
8556
|
// bin/delete.ts
|
|
8553
8557
|
var import_chalk24 = __toESM(require("chalk"));
|
|
8554
8558
|
var import_inquirer9 = __toESM(require("inquirer"));
|
|
8555
|
-
var
|
|
8556
|
-
var
|
|
8559
|
+
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
8560
|
+
var import_path16 = __toESM(require("path"));
|
|
8557
8561
|
function getProjectName() {
|
|
8558
|
-
const configPath =
|
|
8559
|
-
if (!
|
|
8562
|
+
const configPath = import_path16.default.join(process.cwd(), "pinme.toml");
|
|
8563
|
+
if (!import_fs_extra11.default.existsSync(configPath)) {
|
|
8560
8564
|
return null;
|
|
8561
8565
|
}
|
|
8562
|
-
const config =
|
|
8566
|
+
const config = import_fs_extra11.default.readFileSync(configPath, "utf-8");
|
|
8563
8567
|
const match = config.match(/project_name\s*=\s*"([^"]+)"/);
|
|
8564
8568
|
return (match == null ? void 0 : match[1]) || null;
|
|
8565
8569
|
}
|