@iksdev/shard-cli 0.1.47 → 0.1.48
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 +67 -12
- package/package.json +1 -1
package/bin/shard.js
CHANGED
|
@@ -701,25 +701,74 @@ 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
|
+
// ── Affichage statut partage actif ─────────────────────────────────────
|
|
706
|
+
const WS = 58;
|
|
707
|
+
const hr = (l, m, r, col) => `${c(col, l + m.repeat(WS) + r)}`;
|
|
708
|
+
const rowS = (content, col) => {
|
|
709
|
+
const vis = content.replace(/\x1b\[[0-9;]*m/g, '');
|
|
710
|
+
const pad = WS - vis.length;
|
|
711
|
+
return `${c(col, '│')}${content}${' '.repeat(Math.max(0, pad))}${c(col, '│')}`;
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
process.stdout.write('\x1Bc');
|
|
715
|
+
console.log('');
|
|
716
|
+
console.log(hr('┌', '─', '┐', '\x1b[32m'));
|
|
717
|
+
const titleShare = '\x1b[1m\x1b[32m' + ' PARTAGE ACTIF' + '\x1b[0m';
|
|
718
|
+
console.log(rowS(titleShare + ' '.repeat(WS - 15), '\x1b[32m'));
|
|
719
|
+
console.log(hr('├', '─', '┤', '\x1b[32m'));
|
|
720
|
+
console.log(rowS('', '\x1b[32m'));
|
|
721
|
+
if (share.url) {
|
|
722
|
+
const urlLabel = ' \x1b[90mURL \x1b[0m \x1b[1m\x1b[97m' + share.url + '\x1b[0m';
|
|
723
|
+
console.log(rowS(urlLabel, '\x1b[32m'));
|
|
724
|
+
}
|
|
725
|
+
if (share.token) {
|
|
726
|
+
const tokLabel = ' \x1b[90mToken \x1b[0m \x1b[36m' + share.token + '\x1b[0m';
|
|
727
|
+
console.log(rowS(tokLabel, '\x1b[32m'));
|
|
728
|
+
}
|
|
729
|
+
const fileLabel = ' \x1b[90mFichier \x1b[0m \x1b[97m' + fileName + '\x1b[0m';
|
|
730
|
+
console.log(rowS(fileLabel, '\x1b[32m'));
|
|
731
|
+
const dlLabel = ' \x1b[90mLimite \x1b[0m \x1b[97m' + (limits && limits > 0 ? String(limits) + ' telechargement(s)' : 'illimite') + '\x1b[0m';
|
|
732
|
+
console.log(rowS(dlLabel, '\x1b[32m'));
|
|
733
|
+
const expLabel = ' \x1b[90mExpire \x1b[0m \x1b[97m' + (temps && temps > 0 ? `dans ${temps} jour(s)` : 'jamais') + '\x1b[0m';
|
|
734
|
+
console.log(rowS(expLabel, '\x1b[32m'));
|
|
735
|
+
console.log(rowS('', '\x1b[32m'));
|
|
736
|
+
console.log(hr('├', '─', '┤', '\x1b[90m'));
|
|
737
|
+
const hint = ' \x1b[90mTape \x1b[0m\x1b[1m\x1b[97m q \x1b[0m\x1b[90m + Entree pour cloture le partage et revenir au menu\x1b[0m';
|
|
738
|
+
console.log(rowS(hint, '\x1b[90m'));
|
|
739
|
+
console.log(hr('└', '─', '┘', '\x1b[90m'));
|
|
740
|
+
console.log('');
|
|
741
|
+
|
|
742
|
+
// Attend soit la fermeture du socket, soit que l'utilisateur tape 'q'
|
|
713
743
|
await new Promise((resolve) => {
|
|
714
|
-
|
|
744
|
+
// Fermeture côté serveur
|
|
745
|
+
relaySocket.on('close', () => resolve('closed'));
|
|
746
|
+
|
|
747
|
+
// Écoute clavier : 'q' + Entrée = clôture manuelle
|
|
748
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
749
|
+
const onLine = (line) => {
|
|
750
|
+
if (line.trim().toLowerCase() === 'q') {
|
|
751
|
+
rl.close();
|
|
752
|
+
resolve('quit');
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
rl.on('line', onLine);
|
|
756
|
+
// Nettoyer si le socket se ferme en premier
|
|
757
|
+
relaySocket.once('close', () => {
|
|
758
|
+
rl.removeListener('line', onLine);
|
|
759
|
+
rl.close();
|
|
760
|
+
});
|
|
715
761
|
});
|
|
762
|
+
|
|
716
763
|
if (heartbeat) {
|
|
717
764
|
clearInterval(heartbeat);
|
|
718
765
|
heartbeat = null;
|
|
719
766
|
}
|
|
767
|
+
await revokeCreatedShare();
|
|
720
768
|
for (const sig of stopSignals) {
|
|
721
769
|
process.off(sig, stopRelayShare);
|
|
722
770
|
}
|
|
771
|
+
closeRelay();
|
|
723
772
|
return;
|
|
724
773
|
} catch (error) {
|
|
725
774
|
if (heartbeat) {
|
|
@@ -1283,18 +1332,24 @@ async function panelShare() {
|
|
|
1283
1332
|
if (parseInt(limits, 10) > 0) flags.limits = limits;
|
|
1284
1333
|
if (parseInt(temps, 10) > 0) flags.temps = temps;
|
|
1285
1334
|
|
|
1286
|
-
|
|
1287
|
-
|
|
1335
|
+
clearScreen();
|
|
1336
|
+
printSubHeader('Partage en cours...');
|
|
1337
|
+
console.log(` ${c(C.gray, 'Connexion au relay...')}\n`);
|
|
1338
|
+
|
|
1288
1339
|
try {
|
|
1289
1340
|
await shareFile([target], flags);
|
|
1290
|
-
|
|
1341
|
+
// shareFile retourne quand l'utilisateur tape 'q' ou que le socket se ferme
|
|
1342
|
+
printSuccess('Partage cloture.');
|
|
1291
1343
|
} catch (err) {
|
|
1292
1344
|
if (err?.data?.code === 'PLAN_FILE_LIMIT_EXCEEDED') {
|
|
1293
1345
|
printPlanLimitBox(err);
|
|
1294
1346
|
} else {
|
|
1295
1347
|
printError(err.message);
|
|
1296
1348
|
}
|
|
1349
|
+
await pressEnter();
|
|
1350
|
+
return;
|
|
1297
1351
|
}
|
|
1352
|
+
|
|
1298
1353
|
await pressEnter();
|
|
1299
1354
|
}
|
|
1300
1355
|
|