Skip to content

Commit 8015b4a

Browse files
authored
Merge pull request #118 from internxt/feat/pb-1780-move-and-rename-items
[PB-1780]: feat/move-and-rename-items
2 parents 26d5aba + 8bf89e1 commit 8015b4a

57 files changed

Lines changed: 1992 additions & 624 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ APP_CRYPTO_SECRET=6KYQBP847D4ATSFA
88
APP_CRYPTO_SECRET2=8Q8VMUE3BJZV87GT
99
APP_MAGIC_IV=d139cb9a2cd17092e79e1861cf9d7023
1010
APP_MAGIC_SALT=38dce0391b49efba88dbc8c39ebf868f0267eb110bb0012ab27dc52a528d61b1d1ed9d76f400ff58e3240028442b1eab9bb84e111d9dadd997982dbde9dbd25e
11-
WEBDAV_SERVER_PORT=3005
1211
RUDDERSTACK_WRITE_KEY=
1312
RUDDERSTACK_DATAPLANE_URL=

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ USAGE
6161
* [`internxt trash restore`](#internxt-trash-restore-1)
6262
* [`internxt upload`](#internxt-upload)
6363
* [`internxt webdav ACTION`](#internxt-webdav-action)
64+
* [`internxt webdav-config ACTION`](#internxt-webdav-config-action)
6465
* [`internxt whoami`](#internxt-whoami)
6566

6667
## `internxt add-cert`
@@ -544,6 +545,34 @@ EXAMPLES
544545

545546
_See code: [src/commands/webdav.ts](https://github.com/internxt/cli/blob/v1.3.0/src/commands/webdav.ts)_
546547

548+
## `internxt webdav-config ACTION`
549+
550+
Edit the configuration of the Internxt CLI WebDav server as the port or the protocol.
551+
552+
```
553+
USAGE
554+
$ internxt webdav-config ACTION [-n] [-p <value>]
555+
556+
FLAGS
557+
-p, --port=<value> The new port that the WebDAV server is going to be have.
558+
559+
HELPER FLAGS
560+
-n, --non-interactive Blocks the cli from being interactive. If passed, the cli will not request data through the
561+
console and will throw errors directly
562+
563+
DESCRIPTION
564+
Edit the configuration of the Internxt CLI WebDav server as the port or the protocol.
565+
566+
EXAMPLES
567+
$ internxt webdav-config set-http
568+
569+
$ internxt webdav-config set-https
570+
571+
$ internxt webdav-config change-port
572+
```
573+
574+
_See code: [src/commands/webdav-config.ts](https://github.com/internxt/cli/blob/v1.3.0/src/commands/webdav-config.ts)_
575+
547576
## `internxt whoami`
548577

549578
Display the current user logged into the Internxt CLI.

WEBDAV.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ Find below the methods that are supported in the latest version of the Internxt
3838
| OPTIONS ||
3939
| GET ||
4040
| HEAD ||
41-
| POST ||
4241
| PUT ||
4342
| DELETE ||
4443
| PROPFIND ||
4544
| PROPPATCH ||
4645
| MKCOL ||
4746
| COPY ||
48-
| MOVE | |
47+
| MOVE | |
4948

5049
## Requisites
5150

@@ -61,6 +60,6 @@ Find below the methods that are supported in the latest version of the Internxt
6160

6261
## Known issues
6362

64-
- We use selfsigned certificates, so all the requests to the WebDav local server are encrypted, since the certificates are selfsigned, many WebDav clients will complain about the certificates trust. You can safely ignore this warning.
63+
- We use self-signed certificates when using HTTPS. This ensures that all requests to the local WebDAV server are encrypted. However, since the certificates are self-signed, many WebDAV clients may show warnings about certificate trust. You can safely ignore these warnings.
6564

66-
- You may encounter issues with the DNS resolution of webdav.local.internxt.com. In such cases, you can safely replace this address with 127.0.0.1, or the corresponding IP where you have deployed the webdav server if you are connecting from another location.
65+
- You may encounter issues with DNS resolution for webdav.local.internxt.com. In such cases, you can safely replace this address with 127.0.0.1 or the IP address where the WebDAV server is deployed if connecting from a different location.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"dependencies": {
4141
"@internxt/inxt-js": "^2.0.11",
4242
"@internxt/lib": "^1.2.1",
43-
"@internxt/sdk": "^1.5.17",
43+
"@internxt/sdk": "^1.5.25",
4444
"@oclif/core": "^3",
4545
"@rudderstack/rudder-sdk-node": "^2.0.7",
4646
"axios": "^1.6.7",

scripts/add-cert.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
#!/bin/bash
22

3-
CERT_PATH=$1
3+
CERT_PATH="$1"
4+
5+
if [[ -z "$CERT_PATH" ]]; then
6+
echo "Usage: $0 path_to_certificate"
7+
exit 1
8+
fi
49

510
if [[ "$OSTYPE" == "darwin"* ]]; then
6-
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain $CERT_PATH
7-
else
8-
sudo cp $CERT_PATH /usr/local/share/ca-certificates/
11+
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "$CERT_PATH"
12+
elif [[ -d "/usr/local/share/ca-certificates/" ]]; then # For Debian-based distributions
13+
sudo cp "$CERT_PATH" /usr/local/share/ca-certificates/
914
sudo update-ca-certificates
10-
fi
15+
elif [[ -d "/etc/pki/ca-trust/source/anchors/" ]]; then # For Fedora-based distribution
16+
sudo cp "$CERT_PATH" /etc/pki/ca-trust/source/anchors/
17+
sudo update-ca-trust -i
18+
elif [[ -d "/etc/ca-certificates/trust-source/anchors/" ]]; then # For Arch Linux and derivatives
19+
sudo cp "$CERT_PATH" /etc/ca-certificates/trust-source/anchors/
20+
sudo trust extract-compat
21+
else
22+
echo "Local certificates folder not found"
23+
exit 1
24+
fi

src/commands/rename.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default class Rename extends Command {
6868
if (isFolder) {
6969
await DriveFolderService.instance.renameFolder({ folderUuid: item.uuid, name: newName });
7070
} else {
71-
await DriveFileService.instance.renameFile({ fileUuid: item.uuid, name: newName });
71+
await DriveFileService.instance.renameFile(item.uuid, { plainName: newName });
7272
}
7373
CLIUtils.success(`${isFolder ? 'Folder' : 'File'} renamed successfully with: ${newName}`);
7474
}

src/commands/webdav-config.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { Args, Command, Flags } from '@oclif/core';
2+
import { ConfigService } from '../services/config.service';
3+
import { CLIUtils } from '../utils/cli.utils';
4+
import { ErrorUtils } from '../utils/errors.utils';
5+
import { NotValidPortError } from '../types/command.types';
6+
import { ValidationService } from '../services/validation.service';
7+
8+
export default class WebDAVConfig extends Command {
9+
static readonly description = 'Edit the configuration of the Internxt CLI WebDav server as the port or the protocol.';
10+
static readonly args = {
11+
action: Args.string({
12+
required: true,
13+
options: ['set-http', 'set-https', 'change-port'],
14+
}),
15+
};
16+
static readonly examples = [
17+
'<%= config.bin %> <%= command.id %> set-http',
18+
'<%= config.bin %> <%= command.id %> set-https',
19+
'<%= config.bin %> <%= command.id %> change-port',
20+
];
21+
static readonly flags = {
22+
...CLIUtils.CommonFlags,
23+
port: Flags.string({
24+
char: 'p',
25+
description: 'The new port that the WebDAV server is going to be have.',
26+
required: false,
27+
}),
28+
};
29+
30+
public async run(): Promise<void> {
31+
const { args, flags } = await this.parse(WebDAVConfig);
32+
const nonInteractive = flags['non-interactive'];
33+
const webdavConfig = await ConfigService.instance.readWebdavConfig();
34+
35+
if (args.action !== 'change-port' && flags['port']) {
36+
CLIUtils.warning('The port flag will be ignored; it can only be used with the "change-port" action.');
37+
}
38+
39+
switch (args.action) {
40+
case 'set-http': {
41+
await ConfigService.instance.saveWebdavConfig({
42+
...webdavConfig,
43+
protocol: 'http',
44+
});
45+
CLIUtils.success('On the next start, the WebDAV server will use HTTP.');
46+
break;
47+
}
48+
49+
case 'set-https': {
50+
await ConfigService.instance.saveWebdavConfig({
51+
...webdavConfig,
52+
protocol: 'https',
53+
});
54+
CLIUtils.success('On the next start, the WebDAV server will use HTTPS.');
55+
break;
56+
}
57+
58+
case 'change-port': {
59+
const newPort = await this.getWebDAVPort(flags['port'], nonInteractive);
60+
await ConfigService.instance.saveWebdavConfig({
61+
...webdavConfig,
62+
port: newPort,
63+
});
64+
CLIUtils.success('For the next start, the Webdav server will be served at the new port: ' + newPort);
65+
break;
66+
}
67+
}
68+
}
69+
70+
async catch(error: Error) {
71+
ErrorUtils.report(error, { command: this.id });
72+
CLIUtils.error(error.message);
73+
this.exit(1);
74+
}
75+
76+
private static readonly MAX_ATTEMPTS = 3;
77+
78+
public getWebDAVPort = async (webdavPortFlag: string | undefined, nonInteractive: boolean): Promise<string> => {
79+
let port = CLIUtils.getValueFromFlag(
80+
{
81+
value: webdavPortFlag,
82+
name: WebDAVConfig.flags['port'].name,
83+
error: new NotValidPortError(),
84+
canBeEmpty: true,
85+
},
86+
nonInteractive,
87+
(port: string) => ValidationService.instance.validateTCPIntegerPort(port),
88+
);
89+
if (!port) {
90+
port = (await this.getNewWebDAVPortInteractively()).trim();
91+
}
92+
return port;
93+
};
94+
95+
public getNewWebDAVPortInteractively = (): Promise<string> => {
96+
return CLIUtils.promptWithAttempts(
97+
{
98+
message: 'What is the new WebDAV server port?',
99+
options: { required: false },
100+
error: new NotValidPortError(),
101+
},
102+
WebDAVConfig.MAX_ATTEMPTS,
103+
(port: string) => ValidationService.instance.validateTCPIntegerPort(port),
104+
);
105+
};
106+
}

src/commands/webdav.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ConfigService } from '../services/config.service';
55
import { AnalyticsService } from '../services/analytics.service';
66
import { AuthService } from '../services/auth.service';
77
import { DriveDatabaseManager } from '../services/database/drive-database-manager.service';
8+
89
export default class Webdav extends Command {
910
static readonly description = 'Enable, disable, restart or get the status of the Internxt CLI WebDav server';
1011

@@ -23,18 +24,24 @@ export default class Webdav extends Command {
2324
options: ['enable', 'disable', 'restart', 'status'],
2425
}),
2526
};
27+
2628
public async enableWebDav() {
2729
CLIUtils.doing('Starting Internxt WebDav server...');
30+
await DriveDatabaseManager.clean();
2831
await PM2Utils.connect();
2932
await PM2Utils.killWebDavServer();
3033
await PM2Utils.startWebDavServer();
3134
CLIUtils.done();
3235
const { status } = await PM2Utils.webdavServerStatus();
36+
const webdavConfigs = await ConfigService.instance.readWebdavConfig();
3337

3438
if (status === 'online') {
3539
ux.log(`\nWebDav server status: ${ux.colorize('green', 'online')}\n`);
3640
CLIUtils.success(
37-
`Internxt WebDav server started successfully on https://${ConfigService.WEBDAV_LOCAL_URL}:${process.env.WEBDAV_SERVER_PORT}`,
41+
`Internxt WebDav server started successfully at ${webdavConfigs.protocol}://${ConfigService.WEBDAV_LOCAL_URL}:${webdavConfigs.port}`,
42+
);
43+
ux.log(
44+
`\n[If the above URL is not working, the WebDAV server can be accessed directly via your localhost IP at: ${webdavConfigs.protocol}://127.0.0.1:${webdavConfigs.port} ]\n`,
3845
);
3946
const authDetails = await AuthService.instance.getAuthDetails();
4047
await AnalyticsService.instance.track('WebDAVEnabled', { app: 'internxt-cli', userId: authDetails.user.uuid });
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { QueryInterface, DataTypes } from 'sequelize';
2+
3+
/** @type {import('sequelize-cli').Migration} */
4+
module.exports = {
5+
async up(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
6+
await queryInterface.addColumn('folders', 'parent_uuid', {
7+
type: Sequelize.UUIDV4,
8+
references: {
9+
model: 'folders',
10+
key: 'uuid',
11+
},
12+
});
13+
await queryInterface.addColumn('files', 'folder_uuid', {
14+
type: Sequelize.UUIDV4,
15+
references: {
16+
model: 'files',
17+
key: 'uuid',
18+
},
19+
});
20+
},
21+
async down(queryInterface: QueryInterface) {
22+
await queryInterface.removeColumn('folders', 'parent_uuid');
23+
await queryInterface.removeColumn('files', 'folder_uuid');
24+
},
25+
};

src/hooks/prerun/auth_check.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { SdkManager } from '../../services/sdk-manager.service';
88
import { AuthService } from '../../services/auth.service';
99
import { MissingCredentialsError } from '../../types/command.types';
1010
import Webdav from '../../commands/webdav';
11+
import WebDAVConfig from '../../commands/webdav-config';
1112

12-
const CommandsToSkip = [Whoami, Login, Logout, Logs, Webdav];
13+
const CommandsToSkip = [Whoami, Login, Logout, Logs, Webdav, WebDAVConfig];
1314
const hook: Hook<'prerun'> = async function (opts) {
1415
if (!CommandsToSkip.map((command) => command.name).includes(opts.Command.name)) {
1516
CLIUtils.doing('Checking credentials');

0 commit comments

Comments
 (0)