nodio-cli 1.1.2 → 1.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodio-cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Nodio distributed storage network",
5
5
  "main": "src/server/index.js",
6
6
  "type": "commonjs",
@@ -5,7 +5,8 @@ const mongoose = require('mongoose');
5
5
  const { getServerConfig } = require('./config');
6
6
  const { buildRoutes } = require('./routes');
7
7
  const authRoutes = require('./routes/auth');
8
- const { NodeModel } = require('./models');
8
+ const { NodeModel, FileModel } = require('./models');
9
+ const verifyToken = require('./middleware/verifyToken');
9
10
  const { markNodeOfflineAndRecover } = require('./services');
10
11
  const { getWalletBalance } = require('../../services/filecoin');
11
12
 
@@ -40,6 +41,19 @@ async function startServer() {
40
41
  app.use('/api/auth', authRoutes);
41
42
  app.use('/api', buildRoutes(config));
42
43
 
44
+ app.get('/api/files', verifyToken, async (req, res, next) => {
45
+ try {
46
+ const files = await FileModel.find({ userId: req.userId })
47
+ .sort({ createdAt: -1 })
48
+ .select('fileId originalName sizeBytes createdAt filecoinBackedUp filecoinCid')
49
+ .lean();
50
+
51
+ res.json({ files });
52
+ } catch (error) {
53
+ next(error);
54
+ }
55
+ });
56
+
43
57
  app.use((error, _req, res, _next) => {
44
58
  const status = error.statusCode || 500;
45
59
  const message = error.message || 'internal server error';
@@ -57,6 +57,19 @@ function buildRoutes(config) {
57
57
  res.json({ ok: true, service: 'nodio-server' });
58
58
  });
59
59
 
60
+ router.get('/files', verifyToken, async (req, res, next) => {
61
+ try {
62
+ const files = await FileModel.find({ userId: req.userId })
63
+ .sort({ createdAt: -1 })
64
+ .select('fileId originalName sizeBytes createdAt filecoinBackedUp filecoinCid')
65
+ .lean();
66
+
67
+ res.json({ files });
68
+ } catch (error) {
69
+ next(error);
70
+ }
71
+ });
72
+
60
73
  router.post('/nodes/register', async (req, res, next) => {
61
74
  try {
62
75
  const { nodeId, deviceKey, nodeKey, knownNodeIds, url, capacityBytes, freeBytes } = req.body;
@@ -129,6 +129,30 @@ async function whoami(options) {
129
129
  console.log(`userId: ${response.data?.userId || session.userId || 'unknown'}`);
130
130
  }
131
131
 
132
+ async function listFiles(options) {
133
+ const serverUrl = options.server;
134
+ const session = await requireSession();
135
+ const api = createApiClient(serverUrl);
136
+ attachSessionToken(api, session);
137
+ const response = await api.get('/files');
138
+ const files = response.data?.files || [];
139
+
140
+ if (files.length === 0) {
141
+ console.log('No files found for this account.');
142
+ return;
143
+ }
144
+
145
+ for (const file of files) {
146
+ console.log(`fileId: ${file.fileId}`);
147
+ console.log(`name: ${file.originalName}`);
148
+ console.log(`sizeBytes: ${file.sizeBytes}`);
149
+ console.log(`createdAt: ${file.createdAt}`);
150
+ console.log(`filecoinBackedUp: ${Boolean(file.filecoinBackedUp)}`);
151
+ console.log(`filecoinCid: ${file.filecoinCid || ''}`);
152
+ console.log('---');
153
+ }
154
+ }
155
+
132
156
  function splitBuffer(buffer, shardSizeBytes) {
133
157
  if (shardSizeBytes <= 0) {
134
158
  throw new Error('shard size must be greater than zero');
@@ -741,5 +765,6 @@ module.exports = {
741
765
  login,
742
766
  register,
743
767
  logout,
744
- whoami
768
+ whoami,
769
+ listFiles
745
770
  };
package/src/user/index.js CHANGED
@@ -1,6 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  const { Command } = require('commander');
3
- const { uploadFile, downloadFile, deleteFile, login, logout, register, whoami } = require('./commands');
3
+ const {
4
+ uploadFile,
5
+ downloadFile,
6
+ deleteFile,
7
+ login,
8
+ logout,
9
+ register,
10
+ whoami,
11
+ listFiles
12
+ } = require('./commands');
4
13
 
5
14
  const program = new Command();
6
15
 
@@ -74,6 +83,14 @@ program
74
83
  await whoami(options);
75
84
  });
76
85
 
86
+ program
87
+ .command('files')
88
+ .description('List files uploaded by the authenticated user')
89
+ .option('--server <url>', 'central server URL', 'https://api.nodio.me')
90
+ .action(async (options) => {
91
+ await listFiles(options);
92
+ });
93
+
77
94
  program.parseAsync(process.argv).catch((error) => {
78
95
  const apiErrorMessage = error.response?.data?.error;
79
96
  if (apiErrorMessage) {