@iksdev/shard-cli 0.1.47 → 0.1.49
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/bin/shard.js +95 -20
- package/package.json +1 -1
package/bin/shard.js
CHANGED
|
@@ -701,25 +701,31 @@ async function shareFile(positionals, flags) {
|
|
|
701
701
|
const n = Number(share.id);
|
|
702
702
|
if (Number.isFinite(n) && n > 0) createdShareId = n;
|
|
703
703
|
}
|
|
704
|
-
console.log(`Partage relay cree pour: ${fileName}`);
|
|
705
|
-
if (share.url) console.log(`URL Shard: ${share.url}`);
|
|
706
|
-
if (share.token) console.log(`Token: ${share.token}`);
|
|
707
|
-
console.log(`Relay client id: ${relayClientId}`);
|
|
708
|
-
console.log(`Relay file id: ${relayFileId}`);
|
|
709
|
-
console.log(`Limite downloads: ${limits && limits > 0 ? limits : 'illimitee'}`);
|
|
710
|
-
console.log(`Expiration: ${temps && temps > 0 ? `${temps} jour(s)` : 'aucune'}`);
|
|
711
|
-
console.log('Laisse cette commande ouverte tant que le partage doit fonctionner.');
|
|
712
704
|
|
|
705
|
+
// Ecran "Partage actif" - affiché après connexion
|
|
706
|
+
printShareActiveScreen(share, fileName, limits, temps);
|
|
707
|
+
|
|
708
|
+
// Attend 'q' + Entree ou fermeture du socket
|
|
713
709
|
await new Promise((resolve) => {
|
|
714
|
-
relaySocket.on('close', () => resolve());
|
|
710
|
+
relaySocket.on('close', () => resolve('closed'));
|
|
711
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
712
|
+
const onLine = (line) => {
|
|
713
|
+
if (line.trim().toLowerCase() === 'q') {
|
|
714
|
+
rl.close();
|
|
715
|
+
resolve('quit');
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
rl.on('line', onLine);
|
|
719
|
+
relaySocket.once('close', () => {
|
|
720
|
+
rl.removeListener('line', onLine);
|
|
721
|
+
try { rl.close(); } catch (_) {}
|
|
722
|
+
});
|
|
715
723
|
});
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
process.off(sig, stopRelayShare);
|
|
722
|
-
}
|
|
724
|
+
|
|
725
|
+
if (heartbeat) { clearInterval(heartbeat); heartbeat = null; }
|
|
726
|
+
await revokeCreatedShare();
|
|
727
|
+
for (const sig of stopSignals) process.off(sig, stopRelayShare);
|
|
728
|
+
closeRelay();
|
|
723
729
|
return;
|
|
724
730
|
} catch (error) {
|
|
725
731
|
if (heartbeat) {
|
|
@@ -1160,7 +1166,7 @@ function hr(left = '├', mid = '─', right = '┤', color = C.gray) {
|
|
|
1160
1166
|
return c(color, `${left}${mid.repeat(W)}${right}`);
|
|
1161
1167
|
}
|
|
1162
1168
|
|
|
1163
|
-
// Ligne avec bordures latérales
|
|
1169
|
+
// Ligne avec bordures latérales
|
|
1164
1170
|
function row(content = '', color = C.gray) {
|
|
1165
1171
|
const vis = strip(content);
|
|
1166
1172
|
const pad = W - vis.length;
|
|
@@ -1174,6 +1180,67 @@ function rowCentered(content, color = C.gray) {
|
|
|
1174
1180
|
return row(' '.repeat(l) + content + ' '.repeat(r), color);
|
|
1175
1181
|
}
|
|
1176
1182
|
|
|
1183
|
+
// ── Écran de partage actif ────────────────────────────────────────────────────
|
|
1184
|
+
|
|
1185
|
+
function printShareActiveScreen(share, fileName, limits, temps) {
|
|
1186
|
+
const GRN = '\x1b[32m';
|
|
1187
|
+
const DGRN = '\x1b[90m'; // gris foncé pour les labels
|
|
1188
|
+
const WHT = '\x1b[97m';
|
|
1189
|
+
const BWHT = '\x1b[1m\x1b[97m';
|
|
1190
|
+
const CYN = '\x1b[36m';
|
|
1191
|
+
const RST = '\x1b[0m';
|
|
1192
|
+
const DIM = '\x1b[2m';
|
|
1193
|
+
|
|
1194
|
+
const LABEL_W = 10; // largeur des labels alignés
|
|
1195
|
+
|
|
1196
|
+
// Tronque proprement une valeur si elle dépasse la largeur dispo
|
|
1197
|
+
const valW = W - 2 - LABEL_W - 2; // bordure + label + espace
|
|
1198
|
+
const trunc = (s) => s.length > valW ? s.slice(0, valW - 1) + '…' : s;
|
|
1199
|
+
|
|
1200
|
+
const rowShare = (label, value, valColor = WHT) => {
|
|
1201
|
+
const lbl = ` ${DGRN}${label.padEnd(LABEL_W)}${RST}`;
|
|
1202
|
+
const val = `${valColor}${trunc(value)}${RST}`;
|
|
1203
|
+
const vis = strip(lbl + val);
|
|
1204
|
+
const pad = W - vis.length;
|
|
1205
|
+
return `${GRN}│${RST}${lbl}${val}${' '.repeat(Math.max(0, pad))}${GRN}│${RST}`;
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
const dlLabel = limits && limits > 0 ? `${limits} telechargement(s)` : 'illimite';
|
|
1209
|
+
const expLabel = temps && temps > 0 ? `dans ${temps} jour(s)` : 'jamais';
|
|
1210
|
+
const dot = ` ${DIM}·${RST} `;
|
|
1211
|
+
|
|
1212
|
+
clearScreen();
|
|
1213
|
+
console.log('');
|
|
1214
|
+
// En-tête
|
|
1215
|
+
console.log(`${GRN}┌${'─'.repeat(W)}┐${RST}`);
|
|
1216
|
+
|
|
1217
|
+
const badge = `${GRN}▸${RST} ${BWHT}PARTAGE ACTIF${RST}`;
|
|
1218
|
+
const badgeVis = strip(badge);
|
|
1219
|
+
const bL = Math.floor((W - badgeVis.length) / 2);
|
|
1220
|
+
const bR = W - badgeVis.length - bL;
|
|
1221
|
+
console.log(`${GRN}│${RST}${' '.repeat(bL)}${badge}${' '.repeat(bR)}${GRN}│${RST}`);
|
|
1222
|
+
|
|
1223
|
+
console.log(`${GRN}├${'─'.repeat(W)}┤${RST}`);
|
|
1224
|
+
|
|
1225
|
+
// Infos
|
|
1226
|
+
console.log(`${GRN}│${RST}${' '.repeat(W)}${GRN}│${RST}`);
|
|
1227
|
+
if (share.url) console.log(rowShare('URL', share.url, BWHT));
|
|
1228
|
+
if (share.token) console.log(rowShare('Token', share.token, CYN));
|
|
1229
|
+
console.log(rowShare('Fichier', fileName, WHT));
|
|
1230
|
+
console.log(rowShare('Limite', dlLabel, WHT));
|
|
1231
|
+
console.log(rowShare('Expire', expLabel, WHT));
|
|
1232
|
+
console.log(`${GRN}│${RST}${' '.repeat(W)}${GRN}│${RST}`);
|
|
1233
|
+
|
|
1234
|
+
// Footer
|
|
1235
|
+
console.log(`${DGRN}├${'─'.repeat(W)}┤${RST}`);
|
|
1236
|
+
const hint = ` Tape ${BWHT}q${RST}${DGRN} + Entree pour cloture et revenir au menu${RST}`;
|
|
1237
|
+
const hintVis = strip(hint);
|
|
1238
|
+
const hPad = W - hintVis.length;
|
|
1239
|
+
console.log(`${DGRN}│${RST}${hint}${' '.repeat(Math.max(0, hPad))}${DGRN}│${RST}`);
|
|
1240
|
+
console.log(`${DGRN}└${'─'.repeat(W)}┘${RST}`);
|
|
1241
|
+
console.log('');
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1177
1244
|
function printPanel(username, plan, statusMsg) {
|
|
1178
1245
|
const now = new Date();
|
|
1179
1246
|
const timeStr = now.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
|
|
@@ -1283,12 +1350,20 @@ async function panelShare() {
|
|
|
1283
1350
|
if (parseInt(limits, 10) > 0) flags.limits = limits;
|
|
1284
1351
|
if (parseInt(temps, 10) > 0) flags.temps = temps;
|
|
1285
1352
|
|
|
1286
|
-
|
|
1287
|
-
|
|
1353
|
+
// Écran de chargement pendant la connexion au relay
|
|
1354
|
+
clearScreen();
|
|
1355
|
+
printSubHeader('Connexion au relay...');
|
|
1356
|
+
console.log(` ${c(C.gray, 'Initialisation du partage, patiente...')}\n`);
|
|
1357
|
+
|
|
1288
1358
|
try {
|
|
1289
1359
|
await shareFile([target], flags);
|
|
1290
|
-
|
|
1360
|
+
// Retour au menu : shareFile a déjà révoqué et fermé
|
|
1361
|
+
clearScreen();
|
|
1362
|
+
printSubHeader('Partager un fichier');
|
|
1363
|
+
printSuccess('Partage cloture avec succes.');
|
|
1291
1364
|
} catch (err) {
|
|
1365
|
+
clearScreen();
|
|
1366
|
+
printSubHeader('Partager un fichier');
|
|
1292
1367
|
if (err?.data?.code === 'PLAN_FILE_LIMIT_EXCEEDED') {
|
|
1293
1368
|
printPlanLimitBox(err);
|
|
1294
1369
|
} else {
|