@into-cps-association/libms 0.3.1
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/.env +9 -0
- package/.eslintignore +6 -0
- package/.eslintrc +53 -0
- package/.madgerc +18 -0
- package/.prettierrc +4 -0
- package/API.md +211 -0
- package/DEVELOPER.md +60 -0
- package/LICENSE.md +301 -0
- package/README.md +119 -0
- package/dist/src/app.module.d.ts +2 -0
- package/dist/src/app.module.js +36 -0
- package/dist/src/app.module.js.map +1 -0
- package/dist/src/bootstrap.d.ts +6 -0
- package/dist/src/bootstrap.js +27 -0
- package/dist/src/bootstrap.js.map +1 -0
- package/dist/src/files/files.module.d.ts +2 -0
- package/dist/src/files/files.module.js +27 -0
- package/dist/src/files/files.module.js.map +1 -0
- package/dist/src/files/interfaces/files.service.interface.d.ts +5 -0
- package/dist/src/files/interfaces/files.service.interface.js +3 -0
- package/dist/src/files/interfaces/files.service.interface.js.map +1 -0
- package/dist/src/files/queries.d.ts +2 -0
- package/dist/src/files/queries.js +47 -0
- package/dist/src/files/queries.js.map +1 -0
- package/dist/src/files/resolvers/files.resolver.d.ts +8 -0
- package/dist/src/files/resolvers/files.resolver.js +49 -0
- package/dist/src/files/resolvers/files.resolver.js.map +1 -0
- package/dist/src/files/services/files-service.factory.d.ts +11 -0
- package/dist/src/files/services/files-service.factory.js +48 -0
- package/dist/src/files/services/files-service.factory.js.map +1 -0
- package/dist/src/files/services/gitlab-files.service.d.ts +12 -0
- package/dist/src/files/services/gitlab-files.service.js +65 -0
- package/dist/src/files/services/gitlab-files.service.js.map +1 -0
- package/dist/src/files/services/local-files.service.d.ts +11 -0
- package/dist/src/files/services/local-files.service.js +77 -0
- package/dist/src/files/services/local-files.service.js.map +1 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/main.js +20 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/types.d.ts +43 -0
- package/dist/src/types.js +181 -0
- package/dist/src/types.js.map +1 -0
- package/dist/test/e2e/app.e2e.spec.d.ts +1 -0
- package/dist/test/e2e/app.e2e.spec.js +36 -0
- package/dist/test/e2e/app.e2e.spec.js.map +1 -0
- package/dist/test/integration/files.service.integration.spec.d.ts +1 -0
- package/dist/test/integration/files.service.integration.spec.js +53 -0
- package/dist/test/integration/files.service.integration.spec.js.map +1 -0
- package/dist/test/testUtil.d.ts +88 -0
- package/dist/test/testUtil.js +182 -0
- package/dist/test/testUtil.js.map +1 -0
- package/dist/test/unit/files-service.factory.unit.spec.d.ts +1 -0
- package/dist/test/unit/files-service.factory.unit.spec.js +40 -0
- package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -0
- package/dist/test/unit/files.resolver.unit.spec.d.ts +1 -0
- package/dist/test/unit/files.resolver.unit.spec.js +56 -0
- package/dist/test/unit/files.resolver.unit.spec.js.map +1 -0
- package/dist/test/unit/gitlab-files.service.unit.spec.d.ts +1 -0
- package/dist/test/unit/gitlab-files.service.unit.spec.js +37 -0
- package/dist/test/unit/gitlab-files.service.unit.spec.js.map +1 -0
- package/dist/test/unit/local-files.service.unit.spec.d.ts +1 -0
- package/dist/test/unit/local-files.service.unit.spec.js +84 -0
- package/dist/test/unit/local-files.service.unit.spec.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest.config.json +30 -0
- package/nest-cli.json +8 -0
- package/package.json +71 -0
- package/src/app.module.ts +24 -0
- package/src/bootstrap.ts +29 -0
- package/src/files/files.module.ts +15 -0
- package/src/files/interfaces/files.service.interface.ts +7 -0
- package/src/files/queries.ts +42 -0
- package/src/files/resolvers/files.resolver.ts +23 -0
- package/src/files/services/files-service.factory.ts +27 -0
- package/src/files/services/gitlab-files.service.ts +65 -0
- package/src/files/services/local-files.service.ts +76 -0
- package/src/main.ts +27 -0
- package/src/schema.gql +58 -0
- package/src/types.ts +92 -0
- package/test/README.md +33 -0
- package/test/coverage/clover.xml +40 -0
- package/test/coverage/coverage-final.json +2 -0
- package/test/coverage/lcov-report/base.css +224 -0
- package/test/coverage/lcov-report/block-navigation.js +87 -0
- package/test/coverage/lcov-report/favicon.png +0 -0
- package/test/coverage/lcov-report/index.html +116 -0
- package/test/coverage/lcov-report/prettify.css +1 -0
- package/test/coverage/lcov-report/prettify.js +2 -0
- package/test/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/test/coverage/lcov-report/sorter.js +196 -0
- package/test/coverage/lcov-report/testUtil.ts.html +655 -0
- package/test/coverage/lcov.info +52 -0
- package/test/data/user2/data/.gitkeep +0 -0
- package/test/data/user2/digital_twins/.gitkeep +0 -0
- package/test/data/user2/functions/.gitkeep +0 -0
- package/test/data/user2/models/.gitkeep +0 -0
- package/test/data/user2/tools/.gitkeep +0 -0
- package/test/data/user2/tools/README.md +1 -0
- package/test/e2e/app.e2e.spec.ts +79 -0
- package/test/integration/files.service.integration.spec.ts +67 -0
- package/test/jest-e2e.json +9 -0
- package/test/starttraefik.bash +11 -0
- package/test/stoptraefik.bash +9 -0
- package/test/testUtil.ts +190 -0
- package/test/unit/files-service.factory.unit.spec.ts +46 -0
- package/test/unit/files.resolver.unit.spec.ts +70 -0
- package/test/unit/gitlab-files.service.unit.spec.ts +46 -0
- package/test/unit/local-files.service.unit.spec.ts +108 -0
- package/tsconfig.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
The **lib microservice** is a simplified file manager providing graphQL API.
|
|
4
|
+
It has three features:
|
|
5
|
+
|
|
6
|
+
* provide a listing of directory contents.
|
|
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
|
+
|
|
27
|
+
## :arrow_down: Install
|
|
28
|
+
|
|
29
|
+
The package is available in Github
|
|
30
|
+
[packages registry](https://github.com/orgs/INTO-CPS-Association/packages).
|
|
31
|
+
|
|
32
|
+
Set the registry and install the package with the following commands
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
sudo npm config set @into-cps-association:registry https://npm.pkg.github.com
|
|
36
|
+
sudo npm install -g @into-cps-association/libms
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The _npm install_ command asks for username and password. The username is
|
|
40
|
+
your Github username and the password is your Github
|
|
41
|
+
[personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).
|
|
42
|
+
In order for the npm to download the package, your personal access token
|
|
43
|
+
needs to have _read:packages_ scope.
|
|
44
|
+
|
|
45
|
+
## :gear: Configure
|
|
46
|
+
|
|
47
|
+
The microservices requires config specified in INI format.
|
|
48
|
+
The template configuration file is:
|
|
49
|
+
|
|
50
|
+
```ini
|
|
51
|
+
PORT='4001'
|
|
52
|
+
MODE='local' or 'gitlab'
|
|
53
|
+
LOCAL_PATH ='/Users/<Username>/DTaaS/files'
|
|
54
|
+
GITLAB_GROUP ='dtaas'
|
|
55
|
+
GITLAB_URL='https://gitlab.com/api/graphql'
|
|
56
|
+
TOKEN='123-sample-token'
|
|
57
|
+
LOG_LEVEL='debug'
|
|
58
|
+
APOLLO_PATH='/lib' or ''
|
|
59
|
+
GRAPHQL_PLAYGROUND='false' or 'true'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The `LOCAL_PATH` variable is the absolute filepath to the
|
|
63
|
+
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,
|
|
73
|
+
|
|
74
|
+
Replace the default values the appropriate values for your setup.
|
|
75
|
+
|
|
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
|
+
## :rocket: Use
|
|
84
|
+
|
|
85
|
+
Display help.
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
libms -h
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The config is saved `.env` file by convention. The **libms** looks for
|
|
92
|
+
`.env` file in the working directory from which it is run.
|
|
93
|
+
If you want to run **libms** without explicitly specifying the configuration
|
|
94
|
+
file, run
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
libms
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
To run **libms** with a custom config file,
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
libms -c FILE-PATH
|
|
104
|
+
libms --config FILE-PATH
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
If the environment file is named something other than `.env`,
|
|
108
|
+
for example as `.env.development`, you can run
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
libms -c ".env.development"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
You can press `Ctl+C` to halt the application.
|
|
115
|
+
|
|
116
|
+
The microservice is available at: 'localhost:PORT/lib'
|
|
117
|
+
|
|
118
|
+
<!-- markdownlint-disable-next-line MD013 -->
|
|
119
|
+
The [API](https://into-cps-association.github.io/DTaaS/development/user/servers/lib/LIB-MS.html) page shows sample queries and responses.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const config_1 = require("@nestjs/config");
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
12
|
+
const apollo_1 = require("@nestjs/apollo");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const files_module_1 = require("./files/files.module");
|
|
15
|
+
let AppModule = class AppModule {
|
|
16
|
+
};
|
|
17
|
+
AppModule = __decorate([
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [
|
|
20
|
+
config_1.ConfigModule.forRoot({
|
|
21
|
+
isGlobal: true,
|
|
22
|
+
}),
|
|
23
|
+
graphql_1.GraphQLModule.forRootAsync({
|
|
24
|
+
driver: apollo_1.ApolloDriver,
|
|
25
|
+
useFactory: (configService) => ({
|
|
26
|
+
autoSchemaFile: (0, path_1.join)(process.cwd(), 'src/schema.gql'),
|
|
27
|
+
path: configService.get('APOLLO_PATH'),
|
|
28
|
+
}),
|
|
29
|
+
inject: [config_1.ConfigService],
|
|
30
|
+
}),
|
|
31
|
+
files_module_1.default,
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
], AppModule);
|
|
35
|
+
exports.default = AppModule;
|
|
36
|
+
//# sourceMappingURL=app.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../src/app.module.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAA6D;AAC7D,2CAAwC;AACxC,6CAAgD;AAChD,2CAA8C;AAC9C,+BAA4B;AAC5B,uDAA+C;AAkBhC,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,SAAS;IAhB7B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,qBAAY,CAAC,OAAO,CAAC;gBACnB,QAAQ,EAAE,IAAI;aACf,CAAC;YACF,uBAAa,CAAC,YAAY,CAAC;gBACzB,MAAM,EAAE,qBAAY;gBACpB,UAAU,EAAE,CAAC,aAA4B,EAAE,EAAE,CAAC,CAAC;oBAC7C,cAAc,EAAE,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC;oBACrD,IAAI,EAAE,aAAa,CAAC,GAAG,CAAS,aAAa,CAAC;iBAC/C,CAAC;gBACF,MAAM,EAAE,CAAC,sBAAa,CAAC;aACxB,CAAC;YACF,sBAAW;SACZ;KACF,CAAC;GACmB,SAAS,CAAG;kBAAZ,SAAS"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@nestjs/core");
|
|
4
|
+
const config_1 = require("@nestjs/config");
|
|
5
|
+
const dotenv = require("dotenv");
|
|
6
|
+
const app_module_1 = require("./app.module");
|
|
7
|
+
async function bootstrap(options) {
|
|
8
|
+
const configFile = dotenv.config({
|
|
9
|
+
path: options?.config ?? '.env',
|
|
10
|
+
override: true,
|
|
11
|
+
});
|
|
12
|
+
if (configFile.error) {
|
|
13
|
+
console.error(configFile.error);
|
|
14
|
+
if (options.runHelp) {
|
|
15
|
+
options.runHelp();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const app = await core_1.NestFactory.create(app_module_1.default);
|
|
22
|
+
const configService = app.get(config_1.ConfigService);
|
|
23
|
+
const port = configService.get('PORT');
|
|
24
|
+
await app.listen(port);
|
|
25
|
+
}
|
|
26
|
+
exports.default = bootstrap;
|
|
27
|
+
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,2CAA+C;AAC/C,iCAAiC;AACjC,6CAAqC;AAOtB,KAAK,UAAU,SAAS,CAAC,OAA0B;IAChE,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,IAAI,EAAE,OAAO,EAAE,MAAM,IAAI,MAAM;QAC/B,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,IAAI,UAAU,CAAC,KAAK,EAAE;QAEpB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,OAAO,CAAC,OAAO,EAAE,CAAC;SACnB;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;IACD,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,oBAAS,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,GAAG,CAAC,GAAG,CAAC,sBAAa,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAS,MAAM,CAAC,CAAC;IAC/C,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAlBD,4BAkBC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const common_1 = require("@nestjs/common");
|
|
10
|
+
const files_resolver_1 = require("./resolvers/files.resolver");
|
|
11
|
+
const gitlab_files_service_1 = require("./services/gitlab-files.service");
|
|
12
|
+
const files_service_factory_1 = require("./services/files-service.factory");
|
|
13
|
+
const local_files_service_1 = require("./services/local-files.service");
|
|
14
|
+
let FilesModule = class FilesModule {
|
|
15
|
+
};
|
|
16
|
+
FilesModule = __decorate([
|
|
17
|
+
(0, common_1.Module)({
|
|
18
|
+
providers: [
|
|
19
|
+
files_resolver_1.default,
|
|
20
|
+
local_files_service_1.default,
|
|
21
|
+
gitlab_files_service_1.default,
|
|
22
|
+
files_service_factory_1.default,
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
], FilesModule);
|
|
26
|
+
exports.default = FilesModule;
|
|
27
|
+
//# sourceMappingURL=files.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.module.js","sourceRoot":"","sources":["../../../src/files/files.module.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAAwC;AACxC,+DAAuD;AACvD,0EAAiE;AACjE,4EAAmE;AACnE,wEAA+D;AAUhD,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,WAAW;IAR/B,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,wBAAa;YACb,6BAAiB;YACjB,8BAAkB;YAClB,+BAAmB;SACpB;KACF,CAAC;GACmB,WAAW,CAAG;kBAAd,WAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.service.interface.js","sourceRoot":"","sources":["../../../../src/files/interfaces/files.service.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReadFileQuery = exports.getDirectoryQuery = void 0;
|
|
4
|
+
const getDirectoryQuery = (domain, parsedPath) => `
|
|
5
|
+
query listDirectory {
|
|
6
|
+
project(fullPath: "${domain}") {
|
|
7
|
+
repository {
|
|
8
|
+
tree(path: "${parsedPath}", recursive: false) {
|
|
9
|
+
blobs {
|
|
10
|
+
edges {
|
|
11
|
+
node {
|
|
12
|
+
name
|
|
13
|
+
type
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
trees {
|
|
18
|
+
edges {
|
|
19
|
+
node {
|
|
20
|
+
name
|
|
21
|
+
type
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
exports.getDirectoryQuery = getDirectoryQuery;
|
|
31
|
+
const getReadFileQuery = (domain, parsedPath) => `
|
|
32
|
+
query readFile {
|
|
33
|
+
project(fullPath: "${domain}") {
|
|
34
|
+
repository {
|
|
35
|
+
blobs(paths: "${parsedPath}") {
|
|
36
|
+
nodes {
|
|
37
|
+
name
|
|
38
|
+
rawBlob
|
|
39
|
+
rawTextBlob
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
exports.getReadFileQuery = getReadFileQuery;
|
|
47
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/files/queries.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,EAAE,CAAC;;yBAEhD,MAAM;;sBAET,UAAU;;;;;;;;;;;;;;;;;;;;;CAqB/B,CAAC;AAzBW,QAAA,iBAAiB,qBAyB5B;AAEK,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,EAAE,CAAC;;yBAE/C,MAAM;;wBAEP,UAAU;;;;;;;;;;CAUjC,CAAC;AAdW,QAAA,gBAAgB,oBAc3B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import FilesServiceFactory from '../services/files-service.factory';
|
|
2
|
+
import { Project } from '../../types';
|
|
3
|
+
export default class FilesResolver {
|
|
4
|
+
private readonly filesService;
|
|
5
|
+
constructor(filesServiceFactory: FilesServiceFactory);
|
|
6
|
+
listDirectory(path: string): Promise<Project>;
|
|
7
|
+
readFile(path: string): Promise<Project>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
16
|
+
const files_service_factory_1 = require("../services/files-service.factory");
|
|
17
|
+
const types_1 = require("../../types");
|
|
18
|
+
let FilesResolver = class FilesResolver {
|
|
19
|
+
filesService;
|
|
20
|
+
constructor(filesServiceFactory) {
|
|
21
|
+
this.filesService = filesServiceFactory.create();
|
|
22
|
+
}
|
|
23
|
+
async listDirectory(path) {
|
|
24
|
+
return this.filesService.listDirectory(path);
|
|
25
|
+
}
|
|
26
|
+
async readFile(path) {
|
|
27
|
+
return this.filesService.readFile(path);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, graphql_1.Query)(() => types_1.Project),
|
|
32
|
+
__param(0, (0, graphql_1.Args)('path')),
|
|
33
|
+
__metadata("design:type", Function),
|
|
34
|
+
__metadata("design:paramtypes", [String]),
|
|
35
|
+
__metadata("design:returntype", Promise)
|
|
36
|
+
], FilesResolver.prototype, "listDirectory", null);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, graphql_1.Query)(() => types_1.Project),
|
|
39
|
+
__param(0, (0, graphql_1.Args)('path')),
|
|
40
|
+
__metadata("design:type", Function),
|
|
41
|
+
__metadata("design:paramtypes", [String]),
|
|
42
|
+
__metadata("design:returntype", Promise)
|
|
43
|
+
], FilesResolver.prototype, "readFile", null);
|
|
44
|
+
FilesResolver = __decorate([
|
|
45
|
+
(0, graphql_1.Resolver)(),
|
|
46
|
+
__metadata("design:paramtypes", [files_service_factory_1.default])
|
|
47
|
+
], FilesResolver);
|
|
48
|
+
exports.default = FilesResolver;
|
|
49
|
+
//# sourceMappingURL=files.resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.resolver.js","sourceRoot":"","sources":["../../../../src/files/resolvers/files.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6CAAwD;AAExD,6EAAoE;AACpE,uCAAsC;AAGvB,IAAM,aAAa,GAAnB,MAAM,aAAa;IACf,YAAY,CAAgB;IAE7C,YAAY,mBAAwC;QAClD,IAAI,CAAC,YAAY,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAC;IACnD,CAAC;IAGK,AAAN,KAAK,CAAC,aAAa,CAAe,IAAY;QAC5C,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAGK,AAAN,KAAK,CAAC,QAAQ,CAAe,IAAY;QACvC,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AARO;IADL,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,eAAO,CAAC;IACA,WAAA,IAAA,cAAI,EAAC,MAAM,CAAC,CAAA;;;;kDAEhC;AAGK;IADL,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,eAAO,CAAC;IACL,WAAA,IAAA,cAAI,EAAC,MAAM,CAAC,CAAA;;;;6CAE3B;AAfkB,aAAa;IADjC,IAAA,kBAAQ,GAAE;qCAIwB,+BAAmB;GAHjC,aAAa,CAgBjC;kBAhBoB,aAAa"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { IFilesService } from '../interfaces/files.service.interface';
|
|
3
|
+
import GitlabFilesService from './gitlab-files.service';
|
|
4
|
+
import LocalFilesService from './local-files.service';
|
|
5
|
+
export default class FilesServiceFactory {
|
|
6
|
+
private configService;
|
|
7
|
+
private gitlabFilesService;
|
|
8
|
+
private localFilesService;
|
|
9
|
+
constructor(configService: ConfigService, gitlabFilesService: GitlabFilesService, localFilesService: LocalFilesService);
|
|
10
|
+
create(): IFilesService;
|
|
11
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const config_1 = require("@nestjs/config");
|
|
17
|
+
const gitlab_files_service_1 = require("./gitlab-files.service");
|
|
18
|
+
const local_files_service_1 = require("./local-files.service");
|
|
19
|
+
let FilesServiceFactory = class FilesServiceFactory {
|
|
20
|
+
configService;
|
|
21
|
+
gitlabFilesService;
|
|
22
|
+
localFilesService;
|
|
23
|
+
constructor(configService, gitlabFilesService, localFilesService) {
|
|
24
|
+
this.configService = configService;
|
|
25
|
+
this.gitlabFilesService = gitlabFilesService;
|
|
26
|
+
this.localFilesService = localFilesService;
|
|
27
|
+
}
|
|
28
|
+
create() {
|
|
29
|
+
const mode = this.configService.get('MODE');
|
|
30
|
+
if (mode === 'local') {
|
|
31
|
+
return this.localFilesService;
|
|
32
|
+
}
|
|
33
|
+
if (mode === 'gitlab') {
|
|
34
|
+
return this.gitlabFilesService;
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`Invalid MODE: ${mode}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
FilesServiceFactory = __decorate([
|
|
40
|
+
(0, common_1.Injectable)(),
|
|
41
|
+
__param(1, (0, common_1.Inject)(gitlab_files_service_1.default)),
|
|
42
|
+
__param(2, (0, common_1.Inject)(local_files_service_1.default)),
|
|
43
|
+
__metadata("design:paramtypes", [config_1.ConfigService,
|
|
44
|
+
gitlab_files_service_1.default,
|
|
45
|
+
local_files_service_1.default])
|
|
46
|
+
], FilesServiceFactory);
|
|
47
|
+
exports.default = FilesServiceFactory;
|
|
48
|
+
//# sourceMappingURL=files-service.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-service.factory.js","sourceRoot":"","sources":["../../../../src/files/services/files-service.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,2CAA+C;AAE/C,iEAAwD;AACxD,+DAAsD;AAGvC,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAG5B;IAC4B;IACD;IAHrC,YACU,aAA4B,EACA,kBAAsC,EACvC,iBAAoC;QAF/D,kBAAa,GAAb,aAAa,CAAe;QACA,uBAAkB,GAAlB,kBAAkB,CAAoB;QACvC,sBAAiB,GAAjB,iBAAiB,CAAmB;IACtE,CAAC;IAGJ,MAAM;QACJ,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,MAAM,CAAC,CAAC;QACpD,IAAI,IAAI,KAAK,OAAO,EAAE;YACpB,OAAO,IAAI,CAAC,iBAAiB,CAAC;SAC/B;QACD,IAAI,IAAI,KAAK,QAAQ,EAAE;YACrB,OAAO,IAAI,CAAC,kBAAkB,CAAC;SAChC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AAnBoB,mBAAmB;IADvC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,8BAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,6BAAiB,CAAC,CAAA;qCAFH,sBAAa;QACoB,8BAAkB;QACpB,6BAAiB;GALtD,mBAAmB,CAmBvC;kBAnBoB,mBAAmB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { Project } from 'src/types';
|
|
3
|
+
import { IFilesService } from '../interfaces/files.service.interface';
|
|
4
|
+
export default class GitlabFilesService implements IFilesService {
|
|
5
|
+
private configService;
|
|
6
|
+
constructor(configService: ConfigService);
|
|
7
|
+
listDirectory(path: string): Promise<Project>;
|
|
8
|
+
readFile(path: string): Promise<Project>;
|
|
9
|
+
private parseArguments;
|
|
10
|
+
private sendRequest;
|
|
11
|
+
private executeQuery;
|
|
12
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
13
|
+
const config_1 = require("@nestjs/config");
|
|
14
|
+
const axios_1 = require("axios");
|
|
15
|
+
const queries_1 = require("../queries");
|
|
16
|
+
let GitlabFilesService = class GitlabFilesService {
|
|
17
|
+
configService;
|
|
18
|
+
constructor(configService) {
|
|
19
|
+
this.configService = configService;
|
|
20
|
+
}
|
|
21
|
+
async listDirectory(path) {
|
|
22
|
+
return this.executeQuery(path, queries_1.getDirectoryQuery);
|
|
23
|
+
}
|
|
24
|
+
async readFile(path) {
|
|
25
|
+
return this.executeQuery(path, queries_1.getReadFileQuery);
|
|
26
|
+
}
|
|
27
|
+
async parseArguments(path) {
|
|
28
|
+
const gitlabGroup = this.configService.get('GITLAB_GROUP');
|
|
29
|
+
const pathParts = path.split('/');
|
|
30
|
+
const project = pathParts[0];
|
|
31
|
+
const domain = project === gitlabGroup ? project : `${gitlabGroup}/${project}`;
|
|
32
|
+
const parsedPath = pathParts.slice(1).join('/');
|
|
33
|
+
return { domain, parsedPath };
|
|
34
|
+
}
|
|
35
|
+
async sendRequest(query) {
|
|
36
|
+
try {
|
|
37
|
+
const response = await (0, axios_1.default)({
|
|
38
|
+
url: 'https://gitlab.com/api/graphql',
|
|
39
|
+
method: 'post',
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
Authorization: `Bearer ${this.configService.get('GITLAB_TOKEN')}`,
|
|
43
|
+
},
|
|
44
|
+
data: {
|
|
45
|
+
query,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return response.data.data.project;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new Error('Invalid query');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async executeQuery(path, getQuery) {
|
|
55
|
+
const { domain, parsedPath } = await this.parseArguments(path);
|
|
56
|
+
const query = getQuery(domain, parsedPath);
|
|
57
|
+
return this.sendRequest(query);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
GitlabFilesService = __decorate([
|
|
61
|
+
(0, common_1.Injectable)(),
|
|
62
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
63
|
+
], GitlabFilesService);
|
|
64
|
+
exports.default = GitlabFilesService;
|
|
65
|
+
//# sourceMappingURL=gitlab-files.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlab-files.service.js","sourceRoot":"","sources":["../../../../src/files/services/gitlab-files.service.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,iCAA0B;AAG1B,wCAAiE;AAKlD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEjB;IAApB,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAEpD,KAAK,CAAC,aAAa,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,2BAAiB,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,0BAAgB,CAAC,CAAC;IACnD,CAAC;IAEO,KAAK,CAAC,cAAc,CAC1B,IAAY;QAEZ,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC3D,MAAM,SAAS,GAAa,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAW,SAAS,CAAC,CAAC,CAAC,CAAC;QAGrC,MAAM,MAAM,GACV,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,OAAO,EAAE,CAAC;QAElE,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAChC,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,KAAa;QACrC,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC;gBAC3B,GAAG,EAAE,gCAAgC;gBACrC,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;iBAClE;gBACD,IAAI,EAAE;oBACJ,KAAK;iBACN;aACF,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;SACnC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;SAClC;IACH,CAAC;IAEO,KAAK,CAAC,YAAY,CACxB,IAAY,EACZ,QAAuB;QAEvB,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC/D,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;CACF,CAAA;AAtDoB,kBAAkB;IADtC,IAAA,mBAAU,GAAE;qCAGwB,sBAAa;GAF7B,kBAAkB,CAsDtC;kBAtDoB,kBAAkB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { Project } from 'src/types';
|
|
3
|
+
import { IFilesService } from '../interfaces/files.service.interface';
|
|
4
|
+
export default class LocalFilesService implements IFilesService {
|
|
5
|
+
private configService;
|
|
6
|
+
constructor(configService: ConfigService);
|
|
7
|
+
listDirectory(path: string): Promise<Project>;
|
|
8
|
+
readFile(path: string): Promise<Project>;
|
|
9
|
+
private static getFileStats;
|
|
10
|
+
private static formatResponse;
|
|
11
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var LocalFilesService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const config_1 = require("@nestjs/config");
|
|
17
|
+
let LocalFilesService = LocalFilesService_1 = class LocalFilesService {
|
|
18
|
+
configService;
|
|
19
|
+
constructor(configService) {
|
|
20
|
+
this.configService = configService;
|
|
21
|
+
}
|
|
22
|
+
async listDirectory(path) {
|
|
23
|
+
const dataPath = this.configService.get('LOCAL_PATH');
|
|
24
|
+
const fullPath = (0, path_1.join)(dataPath, path);
|
|
25
|
+
const files = await fs.promises.readdir(fullPath);
|
|
26
|
+
const edges = await Promise.all(files.map((file) => LocalFilesService_1.getFileStats(fullPath, file)));
|
|
27
|
+
const tree = {
|
|
28
|
+
trees: {
|
|
29
|
+
edges: edges.filter((edge) => edge.node.type === 'tree'),
|
|
30
|
+
},
|
|
31
|
+
blobs: {
|
|
32
|
+
edges: edges.filter((edge) => edge.node.type === 'blob'),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
return { repository: { tree } };
|
|
36
|
+
}
|
|
37
|
+
async readFile(path) {
|
|
38
|
+
const dataPath = this.configService.get('LOCAL_PATH');
|
|
39
|
+
const fullpath = (0, path_1.join)(dataPath, path);
|
|
40
|
+
try {
|
|
41
|
+
const content = await (await fs.promises.readFile(fullpath, 'utf8')).trim();
|
|
42
|
+
const name = path.split('/').pop();
|
|
43
|
+
return LocalFilesService_1.formatResponse(name, content);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new common_1.InternalServerErrorException('Error reading file');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
static async getFileStats(fullPath, file) {
|
|
50
|
+
const stats = await fs.promises.lstat((0, path_1.join)(fullPath, file));
|
|
51
|
+
if (stats.isDirectory()) {
|
|
52
|
+
return { node: { name: file, type: 'tree' } };
|
|
53
|
+
}
|
|
54
|
+
return { node: { name: file, type: 'blob' } };
|
|
55
|
+
}
|
|
56
|
+
static formatResponse(name, content) {
|
|
57
|
+
return {
|
|
58
|
+
repository: {
|
|
59
|
+
blobs: {
|
|
60
|
+
nodes: [
|
|
61
|
+
{
|
|
62
|
+
name,
|
|
63
|
+
rawBlob: content,
|
|
64
|
+
rawTextBlob: content,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
LocalFilesService = LocalFilesService_1 = __decorate([
|
|
73
|
+
(0, common_1.Injectable)(),
|
|
74
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
75
|
+
], LocalFilesService);
|
|
76
|
+
exports.default = LocalFilesService;
|
|
77
|
+
//# sourceMappingURL=local-files.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-files.service.js","sourceRoot":"","sources":["../../../../src/files/services/local-files.service.ts"],"names":[],"mappings":"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"}
|
package/dist/src/main.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const bootstrap_1 = require("./bootstrap");
|
|
6
|
+
const program = new commander_1.Command();
|
|
7
|
+
program
|
|
8
|
+
.description('The lib microservice is responsible for handling and serving the contents of library assets of the DTaaS platform. It provides API endpoints for clients to query, and fetch these assets.')
|
|
9
|
+
.option('-c, --config <path>', 'set the config path (default .env)')
|
|
10
|
+
.helpOption('-h, --help', 'display help for libms')
|
|
11
|
+
.showHelpAfterError();
|
|
12
|
+
program.parse(process.argv);
|
|
13
|
+
const options = program.opts();
|
|
14
|
+
if (options.config) {
|
|
15
|
+
(0, bootstrap_1.default)({ config: options.config, runHelp: () => program.help() });
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
(0, bootstrap_1.default)({ runHelp: () => program.help() });
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=main.js.map
|