@into-cps-association/libms 0.3.1 → 0.4.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/DEVELOPER.md +24 -7
- package/README.md +42 -43
- package/config/.env.default +6 -0
- package/config/http.json +30 -0
- package/package.json +41 -31
- package/pm2.config.js +10 -0
- package/src/bootstrap.ts +8 -0
- package/src/cloudcmd/cloudcmd.ts +32 -0
- package/src/files/files.module.ts +1 -7
- package/src/files/services/files-service.factory.ts +0 -5
- package/src/files/services/local-files.service.ts +2 -2
- package/src/main.ts +12 -7
- package/test/cloudcmd/cloudcmd.spec.ts +52 -0
- package/test/e2e/app.e2e.spec.ts +42 -42
- package/test/integration/files.service.integration.spec.ts +1 -3
- package/test/testUtil.ts +1 -10
- package/test/unit/files-service.factory.unit.spec.ts +0 -9
- package/tsconfig.json +1 -1
- package/.env +0 -9
- package/dist/src/app.module.d.ts +0 -2
- package/dist/src/app.module.js +0 -36
- package/dist/src/app.module.js.map +0 -1
- package/dist/src/bootstrap.d.ts +0 -6
- package/dist/src/bootstrap.js +0 -27
- package/dist/src/bootstrap.js.map +0 -1
- package/dist/src/files/files.module.d.ts +0 -2
- package/dist/src/files/files.module.js +0 -27
- package/dist/src/files/files.module.js.map +0 -1
- package/dist/src/files/interfaces/files.service.interface.d.ts +0 -5
- package/dist/src/files/interfaces/files.service.interface.js +0 -3
- package/dist/src/files/interfaces/files.service.interface.js.map +0 -1
- package/dist/src/files/queries.d.ts +0 -2
- package/dist/src/files/queries.js +0 -47
- package/dist/src/files/queries.js.map +0 -1
- package/dist/src/files/resolvers/files.resolver.d.ts +0 -8
- package/dist/src/files/resolvers/files.resolver.js +0 -49
- package/dist/src/files/resolvers/files.resolver.js.map +0 -1
- package/dist/src/files/services/files-service.factory.d.ts +0 -11
- package/dist/src/files/services/files-service.factory.js +0 -48
- package/dist/src/files/services/files-service.factory.js.map +0 -1
- package/dist/src/files/services/gitlab-files.service.d.ts +0 -12
- package/dist/src/files/services/gitlab-files.service.js +0 -65
- package/dist/src/files/services/gitlab-files.service.js.map +0 -1
- package/dist/src/files/services/local-files.service.d.ts +0 -11
- package/dist/src/files/services/local-files.service.js +0 -77
- package/dist/src/files/services/local-files.service.js.map +0 -1
- package/dist/src/main.d.ts +0 -2
- package/dist/src/main.js +0 -20
- package/dist/src/main.js.map +0 -1
- package/dist/src/types.d.ts +0 -43
- package/dist/src/types.js +0 -181
- package/dist/src/types.js.map +0 -1
- package/dist/test/e2e/app.e2e.spec.d.ts +0 -1
- package/dist/test/e2e/app.e2e.spec.js +0 -36
- package/dist/test/e2e/app.e2e.spec.js.map +0 -1
- package/dist/test/integration/files.service.integration.spec.d.ts +0 -1
- package/dist/test/integration/files.service.integration.spec.js +0 -53
- package/dist/test/integration/files.service.integration.spec.js.map +0 -1
- package/dist/test/testUtil.d.ts +0 -88
- package/dist/test/testUtil.js +0 -182
- package/dist/test/testUtil.js.map +0 -1
- package/dist/test/unit/files-service.factory.unit.spec.d.ts +0 -1
- package/dist/test/unit/files-service.factory.unit.spec.js +0 -40
- package/dist/test/unit/files-service.factory.unit.spec.js.map +0 -1
- package/dist/test/unit/files.resolver.unit.spec.d.ts +0 -1
- package/dist/test/unit/files.resolver.unit.spec.js +0 -56
- package/dist/test/unit/files.resolver.unit.spec.js.map +0 -1
- package/dist/test/unit/gitlab-files.service.unit.spec.d.ts +0 -1
- package/dist/test/unit/gitlab-files.service.unit.spec.js +0 -37
- package/dist/test/unit/gitlab-files.service.unit.spec.js.map +0 -1
- package/dist/test/unit/local-files.service.unit.spec.d.ts +0 -1
- package/dist/test/unit/local-files.service.unit.spec.js +0 -84
- package/dist/test/unit/local-files.service.unit.spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/files/queries.ts +0 -42
- package/src/files/services/gitlab-files.service.ts +0 -65
- package/test/coverage/clover.xml +0 -40
- package/test/coverage/coverage-final.json +0 -2
- package/test/coverage/lcov-report/base.css +0 -224
- package/test/coverage/lcov-report/block-navigation.js +0 -87
- package/test/coverage/lcov-report/favicon.png +0 -0
- package/test/coverage/lcov-report/index.html +0 -116
- package/test/coverage/lcov-report/prettify.css +0 -1
- package/test/coverage/lcov-report/prettify.js +0 -2
- package/test/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/test/coverage/lcov-report/sorter.js +0 -196
- package/test/coverage/lcov-report/testUtil.ts.html +0 -655
- package/test/coverage/lcov.info +0 -52
- package/test/starttraefik.bash +0 -11
- package/test/stoptraefik.bash +0 -9
- package/test/unit/gitlab-files.service.unit.spec.ts +0 -46
package/DEVELOPER.md
CHANGED
|
@@ -10,32 +10,49 @@ file. Please see [README](./README.md) for this information.
|
|
|
10
10
|
```bash
|
|
11
11
|
yarn install # Install dependencies for the microservice
|
|
12
12
|
yarn syntax # Analyze code for errors and style issues
|
|
13
|
+
yarn format #format .ts[x] and .js[x] files with prettier
|
|
13
14
|
yarn graph # Generate dependency graphs in the code
|
|
14
15
|
yarn build # Compile ES6 to ES5 and copy JS files to build/ directory
|
|
15
|
-
yarn test:unit # Run
|
|
16
|
-
yarn test:e2e # Run end-to-end tests
|
|
16
|
+
yarn test:unit # Run unit tests
|
|
17
17
|
yarn test:int # Run integration tests
|
|
18
|
-
yarn test:
|
|
18
|
+
yarn test:e2e # Run end-to-end tests
|
|
19
|
+
yarn test:http # Run tests for HTTP file service provided by cloudcmd
|
|
20
|
+
yarn test:all # Run all tests except http tests
|
|
19
21
|
yarn start -h # List of all the CLI commands
|
|
20
22
|
yarn start # Start the application
|
|
23
|
+
yarn start:pm2 # Start the application with process manager 2
|
|
24
|
+
yarn stop:pm2 # Stop the application managed by process manager 2
|
|
21
25
|
yarn clean # Deletes "build", "coverage", "dist" and other temp files
|
|
22
26
|
```
|
|
23
27
|
|
|
28
|
+
**NOTE:** The integration, end-to-end and http tests require a valid
|
|
29
|
+
`.env` file. Here is a sample file.
|
|
30
|
+
|
|
31
|
+
```ini
|
|
32
|
+
PORT='4001'
|
|
33
|
+
MODE='local'
|
|
34
|
+
LOCAL_PATH ='/Users/<Username>/DTaaS/files'
|
|
35
|
+
LOG_LEVEL='debug'
|
|
36
|
+
APOLLO_PATH='/lib'
|
|
37
|
+
GRAPHQL_PLAYGROUND='true'
|
|
38
|
+
```
|
|
39
|
+
|
|
24
40
|
## :package: :ship: NPM package
|
|
25
41
|
|
|
26
42
|
### Github Package Registry
|
|
27
43
|
|
|
28
44
|
The Github actions workflow of
|
|
29
|
-
[lib microservice](../../.github/workflows/lib-ms.yml) publishes the
|
|
30
|
-
into
|
|
45
|
+
[lib microservice](../../.github/workflows/lib-ms.yml) publishes the **libms**
|
|
46
|
+
into
|
|
47
|
+
[packages](https://github.com/orgs/INTO-CPS-Association/packages?repo_name=DTaaS).
|
|
31
48
|
|
|
32
49
|
### Verdaccio - Local Package Registry
|
|
33
50
|
|
|
34
51
|
Use the instructions in
|
|
35
52
|
[publish npm package](../../docs/developer/npm-packages.md) for help
|
|
36
|
-
with publishing
|
|
53
|
+
with publishing **libms npm package** in local computer.
|
|
37
54
|
|
|
38
|
-
Application of the advice given on that page for
|
|
55
|
+
Application of the advice given on that page for **libms** will require
|
|
39
56
|
running the following commands.
|
|
40
57
|
|
|
41
58
|
### Publish
|
package/README.md
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
# Overview
|
|
2
2
|
|
|
3
3
|
The **lib microservice** is a simplified file manager providing graphQL API.
|
|
4
|
-
It has
|
|
4
|
+
It has two features:
|
|
5
5
|
|
|
6
6
|
* provide a listing of directory contents.
|
|
7
7
|
* transfer a file to user.
|
|
8
|
-
* Source files can either come from local file system or from a gitlab instance.
|
|
9
|
-
|
|
10
|
-
## Gitlab setup
|
|
11
|
-
|
|
12
|
-
For this microserivce to be functional,
|
|
13
|
-
a certain directory or gitlab project structure is expected.
|
|
14
|
-
The microservice expects that the gitlab consisting of one group, dtaas (by convention),
|
|
15
|
-
and within that group, all of the projects be located,
|
|
16
|
-
**user1**, **user2**, ... , as well as a **commons** projects.
|
|
17
|
-
Each project corresponds to files of one user.
|
|
18
|
-
A sample file structure can be seen in [gitlab dtaas group](https://gitlab.com/dtaas).
|
|
19
|
-
You can visit the gitlab documentation on
|
|
20
|
-
[groups](https://docs.gitlab.com/ee/user/group/)
|
|
21
|
-
for help on the management of gitlab groups.
|
|
22
|
-
|
|
23
|
-
You can clone the git repositories from
|
|
24
|
-
the [gitlab dtaas](https://gitlab.com/dtaas) group
|
|
25
|
-
to get a sample file system structure for the lib microservice.
|
|
26
8
|
|
|
27
9
|
## :arrow_down: Install
|
|
28
10
|
|
|
@@ -51,9 +33,6 @@ The template configuration file is:
|
|
|
51
33
|
PORT='4001'
|
|
52
34
|
MODE='local' or 'gitlab'
|
|
53
35
|
LOCAL_PATH ='/Users/<Username>/DTaaS/files'
|
|
54
|
-
GITLAB_GROUP ='dtaas'
|
|
55
|
-
GITLAB_URL='https://gitlab.com/api/graphql'
|
|
56
|
-
TOKEN='123-sample-token'
|
|
57
36
|
LOG_LEVEL='debug'
|
|
58
37
|
APOLLO_PATH='/lib' or ''
|
|
59
38
|
GRAPHQL_PLAYGROUND='false' or 'true'
|
|
@@ -61,34 +40,34 @@ GRAPHQL_PLAYGROUND='false' or 'true'
|
|
|
61
40
|
|
|
62
41
|
The `LOCAL_PATH` variable is the absolute filepath to the
|
|
63
42
|
location of the local directory which will be served to users
|
|
64
|
-
by the Library microservice.
|
|
65
|
-
|
|
66
|
-
The `GITLAB_URL`, `GITLAB_GROUP` and `TOKEN` are only relevant for `gitlab` mode.
|
|
67
|
-
The `TOKEN` should be set to your GitLab Group access API token.
|
|
68
|
-
For more information on how to create and use your access token,
|
|
69
|
-
[gitlab page](https://docs.gitlab.com/ee/user/group/settings/group_access_tokens.html).
|
|
70
|
-
|
|
71
|
-
Once you've generated a token, copy it and replace
|
|
72
|
-
the value of `TOKEN` with your token for the gitlab group,
|
|
43
|
+
by the Library microservice. This
|
|
44
|
+
[sample configuration file](./config/.env.default) can be used.
|
|
73
45
|
|
|
74
46
|
Replace the default values the appropriate values for your setup.
|
|
75
47
|
|
|
76
|
-
**NOTE**:
|
|
77
|
-
|
|
78
|
-
1. When \__MODE=local_, only _LOCAL_PATH_ is used.
|
|
79
|
-
Other environment variables are unused.
|
|
80
|
-
1. When _MODE=gitlab_, _GITLAB_URL, TOKEN_,
|
|
81
|
-
and _GITLAB_GROUP_ are used; _LOCAL_PATH_ is unused.
|
|
82
|
-
|
|
83
48
|
## :rocket: Use
|
|
84
49
|
|
|
85
50
|
Display help.
|
|
86
51
|
|
|
87
52
|
```bash
|
|
88
|
-
libms -h
|
|
53
|
+
$libms -h
|
|
54
|
+
Usage: libms [options]
|
|
55
|
+
|
|
56
|
+
The lib microservice is a file server. It supports file transfer
|
|
57
|
+
over GraphQL and HTTP protocols.
|
|
58
|
+
|
|
59
|
+
Options:
|
|
60
|
+
-c, --config <file> provide the config file (default .env)
|
|
61
|
+
-H, --http <file> enable the HTTP server with the specified config
|
|
62
|
+
-h, --help display help for libms
|
|
89
63
|
```
|
|
90
64
|
|
|
91
|
-
|
|
65
|
+
Both the options are not mandatory.
|
|
66
|
+
|
|
67
|
+
### Configuration file
|
|
68
|
+
|
|
69
|
+
The config is saved `.env` file by convention. If `-c` is not specified
|
|
70
|
+
The **libms** looks for
|
|
92
71
|
`.env` file in the working directory from which it is run.
|
|
93
72
|
If you want to run **libms** without explicitly specifying the configuration
|
|
94
73
|
file, run
|
|
@@ -105,15 +84,35 @@ libms --config FILE-PATH
|
|
|
105
84
|
```
|
|
106
85
|
|
|
107
86
|
If the environment file is named something other than `.env`,
|
|
108
|
-
for example as
|
|
87
|
+
for example as `config/.env.default`, you can run
|
|
109
88
|
|
|
110
89
|
```sh
|
|
111
|
-
libms -c "
|
|
90
|
+
libms -c "config/.env.default"
|
|
112
91
|
```
|
|
113
92
|
|
|
114
93
|
You can press `Ctl+C` to halt the application.
|
|
115
94
|
|
|
116
|
-
|
|
95
|
+
### Protocol Support
|
|
96
|
+
|
|
97
|
+
The **libms** supports GraphQL protocol by default.
|
|
98
|
+
It is possible to enable the HTTP protocol by setting
|
|
99
|
+
the `-H` option.
|
|
100
|
+
|
|
101
|
+
To run **libms** with a custom config for HTTP protocol, use
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
libms -H FILE-PATH
|
|
105
|
+
libms --http FILE-PATH
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
A sample configuration is [available](./config/http.json).
|
|
109
|
+
|
|
110
|
+
### Accessible URLs
|
|
111
|
+
|
|
112
|
+
The microservice is available at:
|
|
113
|
+
|
|
114
|
+
**GraphQL protocol**: 'localhost:PORT/lib'
|
|
115
|
+
**HTTP protocol**: 'localhost:PORT/lib/files'
|
|
117
116
|
|
|
118
117
|
<!-- markdownlint-disable-next-line MD013 -->
|
|
119
118
|
The [API](https://into-cps-association.github.io/DTaaS/development/user/servers/lib/LIB-MS.html) page shows sample queries and responses.
|
package/config/http.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "DTaaS Fileserver",
|
|
3
|
+
"auth": false,
|
|
4
|
+
"editor": "edward",
|
|
5
|
+
"packer": "zip",
|
|
6
|
+
"diff": true,
|
|
7
|
+
"zip": true,
|
|
8
|
+
"buffer": true,
|
|
9
|
+
"dirStorage": true,
|
|
10
|
+
"online": false,
|
|
11
|
+
"open": false,
|
|
12
|
+
"oneFilePanel": true,
|
|
13
|
+
"keysPanel": false,
|
|
14
|
+
"prefix": "/lib/files",
|
|
15
|
+
"confirmCopy": true,
|
|
16
|
+
"confirmMove": true,
|
|
17
|
+
"showConfig": false,
|
|
18
|
+
"showFileName": true,
|
|
19
|
+
"contact": false,
|
|
20
|
+
"configDialog": false,
|
|
21
|
+
"console": false,
|
|
22
|
+
"terminal": false,
|
|
23
|
+
"vim": false,
|
|
24
|
+
"columns": "name-size-date-owner-mode",
|
|
25
|
+
"export": false,
|
|
26
|
+
"import": false,
|
|
27
|
+
"dropbox": false,
|
|
28
|
+
"dropboxToken": "",
|
|
29
|
+
"log": true
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@into-cps-association/libms",
|
|
3
|
-
"version": "0.3
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "microservices that handles request by fetching and returning the file-names and folders of given directory",
|
|
5
5
|
"author": "phillip.boe.jensen@gmail.com",
|
|
6
6
|
"contributors": [
|
|
@@ -16,53 +16,63 @@
|
|
|
16
16
|
"format": "prettier --ignore-path ../.gitignore --write \"**/*.{ts,tsx,css,scss}\"",
|
|
17
17
|
"graph": "npx madge --image src.svg src && npx madge --image test.svg test",
|
|
18
18
|
"start": "node dist/src/main.js",
|
|
19
|
+
"start:pm2": "pm2 start pm2.config.js",
|
|
20
|
+
"stop:pm2": "pm2 delete libms",
|
|
19
21
|
"syntax": "npx eslint . --fix",
|
|
20
22
|
"pretest": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/README.md",
|
|
21
|
-
"
|
|
22
|
-
"test:
|
|
23
|
-
"test:
|
|
24
|
-
"test:
|
|
23
|
+
"posttest": "npx rimraf ../../files/user2/tools/README.md",
|
|
24
|
+
"test:all": "npx cross-env LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage",
|
|
25
|
+
"test:e2e": "npx cross-env LOCAL_PATH=test/data jest --config ./test/jest-e2e.json --coverage",
|
|
26
|
+
"test:http": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage --coverageThreshold=\"{}\" && pm2 delete libms-test",
|
|
27
|
+
"test:http-nocov": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage=false && pm2 delete libms-test",
|
|
28
|
+
"test:http-github": "yarn build && yarn start:pm2 && jest test/cloudcmd --coverage --coverageThreshold=\"{}\" && pm2 delete libms",
|
|
29
|
+
"test:int": "npx cross-env LOCAL_PATH=test/data jest ../test/integration --coverage",
|
|
30
|
+
"test:nocov": "yarn test:http-nocov && npx cross-env LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage=false",
|
|
31
|
+
"test:unit": "npx cross-env LOCAL_PATH=test/data jest ../test/unit --coverage"
|
|
25
32
|
},
|
|
26
33
|
"bin": "./dist/src/main.js",
|
|
27
34
|
"dependencies": {
|
|
28
|
-
"@apollo/client": "^3.8.
|
|
29
|
-
"@apollo/server": "^4.
|
|
30
|
-
"@nestjs/apollo": "^12.0.
|
|
31
|
-
"@nestjs/common": "^10.
|
|
32
|
-
"@nestjs/config": "^3.
|
|
33
|
-
"@nestjs/core": "^10.
|
|
34
|
-
"@nestjs/graphql": "^12.0.
|
|
35
|
-
"@nestjs/platform-express": "^10.
|
|
35
|
+
"@apollo/client": "^3.8.9",
|
|
36
|
+
"@apollo/server": "^4.10.0",
|
|
37
|
+
"@nestjs/apollo": "^12.0.11",
|
|
38
|
+
"@nestjs/common": "^10.3.7",
|
|
39
|
+
"@nestjs/config": "^3.2.0",
|
|
40
|
+
"@nestjs/core": "^10.3.3",
|
|
41
|
+
"@nestjs/graphql": "^12.0.11",
|
|
42
|
+
"@nestjs/platform-express": "^10.3.7",
|
|
36
43
|
"axios": "^1.5.1",
|
|
44
|
+
"cloudcmd": "^16.17.7",
|
|
37
45
|
"commander": "^11.1.0",
|
|
38
46
|
"dotenv": "^16.3.1",
|
|
39
|
-
"express": "^4.18.2",
|
|
40
47
|
"graphql": "^16.8.1",
|
|
41
48
|
"mock-fs": "^5.2.0",
|
|
42
|
-
"reflect-metadata": "^0.1
|
|
49
|
+
"reflect-metadata": "^0.2.1",
|
|
43
50
|
"rxjs": "^7.8.1",
|
|
51
|
+
"socket.io": "^4.7.2",
|
|
44
52
|
"type-graphql": "^2.0.0-beta.3"
|
|
45
53
|
},
|
|
46
54
|
"devDependencies": {
|
|
47
|
-
"@nestjs/cli": "^10.
|
|
48
|
-
"@nestjs/schematics": "^10.
|
|
49
|
-
"@nestjs/testing": "^10.
|
|
50
|
-
"@types/express": "^4.17.
|
|
51
|
-
"@types/jest": "^29.5.
|
|
52
|
-
"@types/node": "20.
|
|
53
|
-
"@types/supertest": "^
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
55
|
-
"@typescript-eslint/parser": "^6.
|
|
56
|
-
"
|
|
55
|
+
"@nestjs/cli": "^10.3.2",
|
|
56
|
+
"@nestjs/schematics": "^10.1.1",
|
|
57
|
+
"@nestjs/testing": "^10.3.3",
|
|
58
|
+
"@types/express": "^4.17.21",
|
|
59
|
+
"@types/jest": "^29.5.12",
|
|
60
|
+
"@types/node": "20.12.5",
|
|
61
|
+
"@types/supertest": "^6.0.2",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
63
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
64
|
+
"cross-fetch": "^4.0.0",
|
|
65
|
+
"eslint": "^8.56.0",
|
|
57
66
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
58
|
-
"eslint-config-prettier": "^9.
|
|
59
|
-
"eslint-plugin-import": "^2.
|
|
60
|
-
"eslint-plugin-jest": "^
|
|
61
|
-
"eslint-plugin-prettier": "^5.
|
|
67
|
+
"eslint-config-prettier": "^9.1.0",
|
|
68
|
+
"eslint-plugin-import": "^2.29.1",
|
|
69
|
+
"eslint-plugin-jest": "^28.2.0",
|
|
70
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
62
71
|
"graphql-scalars": "^1.22.2",
|
|
63
72
|
"jest": "29.7.0",
|
|
64
|
-
"prettier": "^3.
|
|
65
|
-
"
|
|
73
|
+
"prettier": "^3.2.2",
|
|
74
|
+
"react": "^18.2.0",
|
|
75
|
+
"supertest": "^6.3.4",
|
|
66
76
|
"ts-jest": "^29.1.1",
|
|
67
77
|
"ts-node": "^10.9.1",
|
|
68
78
|
"tsconfig-paths": "4.2.0",
|
package/pm2.config.js
ADDED
package/src/bootstrap.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { NestFactory } from '@nestjs/core';
|
|
|
2
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
3
|
import * as dotenv from 'dotenv';
|
|
4
4
|
import AppModule from './app.module';
|
|
5
|
+
import cloudCMD from './cloudcmd/cloudcmd';
|
|
5
6
|
|
|
6
7
|
type BootstrapOptions = {
|
|
7
8
|
config?: string;
|
|
9
|
+
httpServer?: string;
|
|
8
10
|
runHelp?: CallableFunction;
|
|
9
11
|
};
|
|
10
12
|
|
|
@@ -22,8 +24,14 @@ export default async function bootstrap(options?: BootstrapOptions) {
|
|
|
22
24
|
process.exit(1);
|
|
23
25
|
}
|
|
24
26
|
}
|
|
27
|
+
|
|
25
28
|
const app = await NestFactory.create(AppModule);
|
|
26
29
|
const configService = app.get(ConfigService);
|
|
27
30
|
const port = configService.get<number>('PORT');
|
|
31
|
+
|
|
32
|
+
if (options.httpServer) {
|
|
33
|
+
cloudCMD(app, options.httpServer, configService.get<string>('LOCAL_PATH'));
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
await app.listen(port);
|
|
29
37
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { INestApplication } from '@nestjs/common';
|
|
2
|
+
import { Server } from 'socket.io';
|
|
3
|
+
import * as cloudcmd from 'cloudcmd';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
const runCloudCMD = (
|
|
7
|
+
app: INestApplication,
|
|
8
|
+
optionsPath: string,
|
|
9
|
+
filesPath: string,
|
|
10
|
+
) => {
|
|
11
|
+
const { createConfigManager } = cloudcmd;
|
|
12
|
+
const configManager = createConfigManager({
|
|
13
|
+
configPath: join(process.cwd(), optionsPath),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
configManager('root', filesPath);
|
|
17
|
+
|
|
18
|
+
const server = app.getHttpServer();
|
|
19
|
+
|
|
20
|
+
const socket = new Server(server, {
|
|
21
|
+
path: `${configManager('prefix')}/socket.io`,
|
|
22
|
+
});
|
|
23
|
+
app.use(
|
|
24
|
+
configManager('prefix'),
|
|
25
|
+
cloudcmd({
|
|
26
|
+
configManager,
|
|
27
|
+
socket,
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default runCloudCMD;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
2
|
import FilesResolver from './resolvers/files.resolver';
|
|
3
|
-
import GitlabFilesService from './services/gitlab-files.service';
|
|
4
3
|
import FilesServiceFactory from './services/files-service.factory';
|
|
5
4
|
import LocalFilesService from './services/local-files.service';
|
|
6
5
|
|
|
7
6
|
@Module({
|
|
8
|
-
providers: [
|
|
9
|
-
FilesResolver,
|
|
10
|
-
LocalFilesService,
|
|
11
|
-
GitlabFilesService,
|
|
12
|
-
FilesServiceFactory,
|
|
13
|
-
],
|
|
7
|
+
providers: [FilesResolver, LocalFilesService, FilesServiceFactory],
|
|
14
8
|
})
|
|
15
9
|
export default class FilesModule {}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Injectable, Inject } from '@nestjs/common';
|
|
2
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
3
|
import { IFilesService } from '../interfaces/files.service.interface';
|
|
4
|
-
import GitlabFilesService from './gitlab-files.service';
|
|
5
4
|
import LocalFilesService from './local-files.service';
|
|
6
5
|
|
|
7
6
|
@Injectable()
|
|
@@ -9,7 +8,6 @@ export default class FilesServiceFactory {
|
|
|
9
8
|
/* eslint-disable no-useless-constructor, no-empty-function */
|
|
10
9
|
constructor(
|
|
11
10
|
private configService: ConfigService,
|
|
12
|
-
@Inject(GitlabFilesService) private gitlabFilesService: GitlabFilesService,
|
|
13
11
|
@Inject(LocalFilesService) private localFilesService: LocalFilesService,
|
|
14
12
|
) {}
|
|
15
13
|
/* eslint-enable no-useless-constructor, no-empty-function */
|
|
@@ -19,9 +17,6 @@ export default class FilesServiceFactory {
|
|
|
19
17
|
if (mode === 'local') {
|
|
20
18
|
return this.localFilesService;
|
|
21
19
|
}
|
|
22
|
-
if (mode === 'gitlab') {
|
|
23
|
-
return this.gitlabFilesService;
|
|
24
|
-
}
|
|
25
20
|
throw new Error(`Invalid MODE: ${mode}`);
|
|
26
21
|
}
|
|
27
22
|
}
|
|
@@ -34,11 +34,11 @@ export default class LocalFilesService implements IFilesService {
|
|
|
34
34
|
|
|
35
35
|
async readFile(path: string): Promise<Project> {
|
|
36
36
|
const dataPath = this.configService.get('LOCAL_PATH');
|
|
37
|
-
const
|
|
37
|
+
const fullPath = join(dataPath, path);
|
|
38
38
|
|
|
39
39
|
try {
|
|
40
40
|
const content = await (
|
|
41
|
-
await fs.promises.readFile(
|
|
41
|
+
await fs.promises.readFile(fullPath, 'utf8')
|
|
42
42
|
).trim();
|
|
43
43
|
|
|
44
44
|
const name = path.split('/').pop(); // extract file name from the path
|
package/src/main.ts
CHANGED
|
@@ -4,15 +4,20 @@ import bootstrap from './bootstrap';
|
|
|
4
4
|
|
|
5
5
|
type ProgramOptions = {
|
|
6
6
|
config?: string;
|
|
7
|
+
http?: string;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
const program = new Command();
|
|
10
11
|
|
|
11
12
|
program
|
|
12
13
|
.description(
|
|
13
|
-
'The lib microservice is
|
|
14
|
+
'The lib microservice is a file server. It supports file transfer over GraphQL and HTTP protocols.',
|
|
15
|
+
)
|
|
16
|
+
.option('-c, --config <file>', 'provide the config file (default .env)')
|
|
17
|
+
.option(
|
|
18
|
+
'-H, --http <file>',
|
|
19
|
+
'enable the HTTP server with the specified config',
|
|
14
20
|
)
|
|
15
|
-
.option('-c, --config <path>', 'set the config path (default .env)')
|
|
16
21
|
.helpOption('-h, --help', 'display help for libms')
|
|
17
22
|
.showHelpAfterError();
|
|
18
23
|
|
|
@@ -20,8 +25,8 @@ program.parse(process.argv);
|
|
|
20
25
|
|
|
21
26
|
const options: ProgramOptions = program.opts();
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
+
bootstrap({
|
|
29
|
+
config: options.config,
|
|
30
|
+
httpServer: options.http,
|
|
31
|
+
runHelp: () => program.help(),
|
|
32
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { unlink, writeFile } from 'fs/promises';
|
|
3
|
+
import { config } from 'dotenv';
|
|
4
|
+
|
|
5
|
+
describe('cloudcmd test for the application', () => {
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
config();
|
|
8
|
+
|
|
9
|
+
await writeFile(`${process.env.LOCAL_PATH}/test.txt`, 'content12345');
|
|
10
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
11
|
+
await new Promise((resolve) => setTimeout(resolve, 8000));
|
|
12
|
+
}, 10000);
|
|
13
|
+
|
|
14
|
+
afterAll(async () => {
|
|
15
|
+
await unlink(`${process.env.LOCAL_PATH}/test.txt`);
|
|
16
|
+
await unlink(`${process.env.LOCAL_PATH}/uploadTest.txt`);
|
|
17
|
+
}, 10000);
|
|
18
|
+
|
|
19
|
+
it('should return the correct directory that is set as root', async () => {
|
|
20
|
+
const response = await axios.get(
|
|
21
|
+
`http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs`,
|
|
22
|
+
{
|
|
23
|
+
responseType: 'json',
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
/* eslint-disable no-console */
|
|
27
|
+
console.log(response.data);
|
|
28
|
+
/* eslint-enable no-console */
|
|
29
|
+
expect(response.data.path).toEqual('/');
|
|
30
|
+
expect(response.data.files[0].name).toEqual('common');
|
|
31
|
+
expect(response.data.files[1].name).toEqual('user1');
|
|
32
|
+
expect(response.data.files[2].name).toEqual('user2');
|
|
33
|
+
}, 10000);
|
|
34
|
+
|
|
35
|
+
it('should return the content of a file that is uplaoded to cloudcmd ', async () => {
|
|
36
|
+
const response = await axios.get(
|
|
37
|
+
`http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs/test.txt`,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(response.data).toEqual('content12345');
|
|
41
|
+
}, 10000);
|
|
42
|
+
|
|
43
|
+
it('should upload a file to cloudcmd', async () => {
|
|
44
|
+
const response = await axios.put(
|
|
45
|
+
`http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs/uploadTest.txt`,
|
|
46
|
+
'some content',
|
|
47
|
+
{ responseType: 'text' },
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(response.data).toEqual('save: ok("uploadTest.txt")');
|
|
51
|
+
}, 10000);
|
|
52
|
+
});
|