underpost 3.2.70 → 3.2.80
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/.github/workflows/publish.ci.yml +3 -3
- package/.github/workflows/release.cd.yml +1 -1
- package/CHANGELOG.md +1177 -1038
- package/CLI-HELP.md +3 -1
- package/README.md +3 -3
- package/bin/build.js +10 -4
- package/docker-compose.yml +1 -1
- package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +1 -1
- package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +1 -1
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/package.json +10 -10
- package/scripts/test-monitor.sh +1 -1
- package/src/api/core/core.controller.js +4 -65
- package/src/api/core/core.router.js +8 -14
- package/src/api/default/default.controller.js +2 -70
- package/src/api/default/default.router.js +7 -17
- package/src/api/document/document.controller.js +5 -77
- package/src/api/document/document.router.js +9 -13
- package/src/api/file/file.controller.js +9 -53
- package/src/api/file/file.router.js +14 -6
- package/src/api/test/test.controller.js +8 -53
- package/src/api/test/test.router.js +1 -4
- package/src/cli/cluster.js +31 -11
- package/src/cli/db.js +4 -2
- package/src/cli/deploy.js +51 -9
- package/src/cli/docker-compose.js +163 -9
- package/src/cli/fs.js +0 -1
- package/src/cli/image.js +25 -7
- package/src/cli/index.js +5 -0
- package/src/cli/release.js +4 -0
- package/src/cli/repository.js +13 -2
- package/src/cli/run.js +151 -78
- package/src/cli/ssh.js +30 -11
- package/src/client/components/core/Modal.js +38 -4
- package/src/index.js +1 -1
- package/src/server/conf.js +163 -0
- package/src/server/downloader.js +3 -3
- package/src/server/middlewares.js +152 -0
package/CLI-HELP.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## Underpost CLI
|
|
2
2
|
|
|
3
|
-
> underpost ci/cd cli v3.2.
|
|
3
|
+
> underpost ci/cd cli v3.2.80
|
|
4
4
|
|
|
5
5
|
**Usage:** `underpost [options] [command]`
|
|
6
6
|
|
|
@@ -210,6 +210,7 @@ Manages commits to a GitHub repository, supporting various commit types and opti
|
|
|
210
210
|
| `--edit` | Edit last commit. |
|
|
211
211
|
| `--deploy-id <deploy-id>` | Sets the deployment configuration ID for the commit context. |
|
|
212
212
|
| `--cached` | Commit staged changes only or context. |
|
|
213
|
+
| `--init-repo [origin]` | Initialize a git repository at the specified path. Optionally set the git remote origin URL. |
|
|
213
214
|
| `--hashes <hashes>` | Comma-separated list of specific file hashes of commits. |
|
|
214
215
|
| `--extension <extension>` | specific file extensions of commits. |
|
|
215
216
|
| `--changelog` | Print the plain changelog of the last N commits (see --from-n-commit, default 1). |
|
|
@@ -901,6 +902,7 @@ Runs specified scripts using various runners.
|
|
|
901
902
|
| `--pull-bundle` | Explicitly download the pre-built client bundle from Cloudinary inside the container (supported by: sync, template-deploy). Use together with --skip-full-build. |
|
|
902
903
|
| `--remove` | Remove/teardown resources |
|
|
903
904
|
| `--test` | Enables test/generic-purpose mode for the runner (e.g. use self-signed TLS instead of cert-manager). |
|
|
905
|
+
| `--branch <branch>` | Sets the branch for git operations (default: current branch). |
|
|
904
906
|
| `-h, --help` | display help for command |
|
|
905
907
|
|
|
906
908
|
---
|
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
<div align="center">
|
|
12
12
|
|
|
13
|
-
<a target="_top" href='https://download.rockylinux.org/pub/rocky/9/'><img alt='rockylinux' src='https://img.shields.io/badge/Rocky Linux v9.
|
|
13
|
+
<a target="_top" href='https://download.rockylinux.org/pub/rocky/9/'><img alt='rockylinux' src='https://img.shields.io/badge/Rocky Linux v9.8-100000?style=flat&logo=rockylinux&logoColor=white&labelColor=10b981&color=727273'/></a> <a target="_top" href='https://www.npmjs.com/package/npm?activeTab=versions'><img alt='npm' src='https://img.shields.io/badge/npm v11.6.2-100000?style=flat&logo=npm&logoColor=white&labelColor=CB3837&color=727273'/></a> <a target="_top" href='https://nodejs.org/download/release'><img alt='nodedotjs' src='https://img.shields.io/badge/node v24.15.0-100000?style=flat&logo=nodedotjs&logoColor=white&labelColor=5FA04E&color=727273'/></a> <a target="_top" href='https://pgp.mongodb.com/'><img alt='mongodb' src='https://img.shields.io/badge/mongodb_server v7.0-100000?style=flat&logo=mongodb&logoColor=white&labelColor=47A248&color=727273'/></a>
|
|
14
14
|
|
|
15
15
|
</div>
|
|
16
16
|
|
|
17
17
|
<div align="center">
|
|
18
18
|
|
|
19
|
-
[](https://github.com/underpostnet/engine/actions/workflows/docker-image.ci.yml) [](https://github.com/underpostnet/engine/actions/workflows/coverall.ci.yml) [](https://www.npmjs.com/package/underpost) [](https://www.jsdelivr.com/package/npm/underpost) [](https://github.com/underpostnet/engine/actions/workflows/docker-image.ci.yml) [](https://github.com/underpostnet/engine/actions/workflows/coverall.ci.yml) [](https://www.npmjs.com/package/underpost) [](https://www.jsdelivr.com/package/npm/underpost) [](https://socket.dev/npm/package/underpost/overview/3.2.80) [](https://coveralls.io/github/underpostnet/engine?branch=master) [](https://www.npmjs.org/package/underpost) [](https://www.npmjs.com/package/underpost)
|
|
20
20
|
|
|
21
21
|
</div>
|
|
22
22
|
|
|
@@ -88,7 +88,7 @@ npm run dev
|
|
|
88
88
|
<!-- cli-index-start -->
|
|
89
89
|
## Underpost CLI
|
|
90
90
|
|
|
91
|
-
> underpost ci/cd cli v3.2.
|
|
91
|
+
> underpost ci/cd cli v3.2.80
|
|
92
92
|
|
|
93
93
|
**Usage:** `underpost [options] [command]`
|
|
94
94
|
|
package/bin/build.js
CHANGED
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
updatePrivateEngineTestRepo,
|
|
15
15
|
} from '../src/server/conf.js';
|
|
16
16
|
import { loadDeployCatalog } from '../src/server/catalog.js';
|
|
17
|
-
import
|
|
17
|
+
import Underpost from '../src/index.js';
|
|
18
|
+
import { DOCKER_SCRIPTS } from '../src/api/cyberia-server-defaults/cyberia-server-defaults.js';
|
|
18
19
|
|
|
19
20
|
const baseConfPath = './engine-private/conf/dd-cron/.env.production';
|
|
20
21
|
if (fs.existsSync(baseConfPath)) dotenv.config({ path: baseConfPath, override: true });
|
|
@@ -34,8 +35,8 @@ const buildDeployTemplate = async (confName) => {
|
|
|
34
35
|
const catalog = await loadDeployCatalog(confName);
|
|
35
36
|
|
|
36
37
|
if (catalog.sourceMoves.length) {
|
|
37
|
-
|
|
38
|
-
if (catalog.sourceMoves.some(([src]) => !fs.existsSync(src)))
|
|
38
|
+
Underpost.repo.sparseCheckoutDirectory(`conf/${confName}`);
|
|
39
|
+
if (catalog.sourceMoves.some(([src]) => !fs.existsSync(src))) Underpost.repo.pullSourceRepo(repoName);
|
|
39
40
|
}
|
|
40
41
|
syncDeployIdSources(catalog.sourceMoves);
|
|
41
42
|
|
|
@@ -125,9 +126,14 @@ const buildDeployTemplate = async (confName) => {
|
|
|
125
126
|
packageJson.description = catalog.description;
|
|
126
127
|
const { CyberiaDependencies } = await import(`../src/api/cyberia-server-defaults/cyberia-server-defaults.js`);
|
|
127
128
|
packageJson.dependencies = {
|
|
128
|
-
|
|
129
|
+
underpost: '^' + Underpost.version.replace('v', ''),
|
|
130
|
+
'adm-zip': '^0.6.0',
|
|
129
131
|
...CyberiaDependencies,
|
|
130
132
|
};
|
|
133
|
+
packageJson.scripts = {
|
|
134
|
+
...packageJson.scripts,
|
|
135
|
+
...DOCKER_SCRIPTS,
|
|
136
|
+
};
|
|
131
137
|
fs.writeFileSync(`${basePath}/bin/index.js`, fs.readFileSync(`./bin/cyberia.js`, 'utf8'), 'utf8');
|
|
132
138
|
// Canonical Cyberia doc; engine-cyberia/README.md is a generated copy — never hand-edited.
|
|
133
139
|
fs.writeFileSync(
|
package/docker-compose.yml
CHANGED
|
@@ -81,7 +81,7 @@ services:
|
|
|
81
81
|
# (dd-default-development-blue). Connection targets use Docker service
|
|
82
82
|
# discovery instead of hardcoded localhost.
|
|
83
83
|
app:
|
|
84
|
-
image: ${APP_IMAGE:-underpost/underpost-engine}:${APP_TAG:-v3.2.
|
|
84
|
+
image: ${APP_IMAGE:-underpost/underpost-engine}:${APP_TAG:-v3.2.80}
|
|
85
85
|
container_name: dd-app
|
|
86
86
|
# The start command is supplied by the generated override docker/compose.app.yml
|
|
87
87
|
# (see `underpost docker-compose --generate --deploy-id <id>`), keeping this
|
|
@@ -17,7 +17,7 @@ spec:
|
|
|
17
17
|
spec:
|
|
18
18
|
containers:
|
|
19
19
|
- name: dd-default-development-blue
|
|
20
|
-
image: underpost/underpost-engine:v3.2.
|
|
20
|
+
image: underpost/underpost-engine:v3.2.80
|
|
21
21
|
# resources:
|
|
22
22
|
# requests:
|
|
23
23
|
# memory: "124Ki"
|
|
@@ -98,7 +98,7 @@ spec:
|
|
|
98
98
|
spec:
|
|
99
99
|
containers:
|
|
100
100
|
- name: dd-default-development-green
|
|
101
|
-
image: underpost/underpost-engine:v3.2.
|
|
101
|
+
image: underpost/underpost-engine:v3.2.80
|
|
102
102
|
# resources:
|
|
103
103
|
# requests:
|
|
104
104
|
# memory: "124Ki"
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"main": "src/index.js",
|
|
4
4
|
"name": "underpost",
|
|
5
|
-
"version": "3.2.
|
|
5
|
+
"version": "3.2.80",
|
|
6
6
|
"description": "Underpost Platform — end-to-end CI/CD and application-delivery toolchain CLI. Covers bare metal, Kubernetes, K3s, kubeadm, LXD, container/image orchestration, secrets, databases, cron jobs, monitoring, SSH, runners, PWA + Workbox delivery, and release orchestration. Extensible via downstream CLIs.",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "node --max-old-space-size=8192 src/server",
|
|
@@ -71,13 +71,13 @@
|
|
|
71
71
|
},
|
|
72
72
|
"homepage": "https://github.com/underpostnet/pwa-microservices-template#readme",
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@fortawesome/fontawesome-free": "^7.3.
|
|
75
|
-
"@fullcalendar/rrule": "^
|
|
74
|
+
"@fortawesome/fontawesome-free": "^7.3.1",
|
|
75
|
+
"@fullcalendar/rrule": "^7.0.1",
|
|
76
76
|
"@grpc/grpc-js": "^1.14.4",
|
|
77
77
|
"@grpc/proto-loader": "^0.8.1",
|
|
78
78
|
"@neodrag/vanilla": "^2.3.1",
|
|
79
|
-
"adm-zip": "^0.
|
|
80
|
-
"ag-grid-community": "^36.0.
|
|
79
|
+
"adm-zip": "^0.6.0",
|
|
80
|
+
"ag-grid-community": "^36.0.1",
|
|
81
81
|
"axios": "^1.18.1",
|
|
82
82
|
"bumpp": "^11.1.0",
|
|
83
83
|
"chai": "^6.2.2",
|
|
@@ -96,13 +96,13 @@
|
|
|
96
96
|
"escape-string-regexp": "^5.0.0",
|
|
97
97
|
"express": "^5.2.1",
|
|
98
98
|
"express-fileupload": "^1.4.3",
|
|
99
|
-
"express-rate-limit": "^8.
|
|
99
|
+
"express-rate-limit": "^8.6.0",
|
|
100
100
|
"express-slow-down": "^3.1.0",
|
|
101
101
|
"fast-json-stable-stringify": "^2.1.0",
|
|
102
102
|
"favicons": "^7.3.0",
|
|
103
103
|
"fs-extra": "^11.3.6",
|
|
104
|
-
"fullcalendar": "^
|
|
105
|
-
"helmet": "^8.
|
|
104
|
+
"fullcalendar": "^7.0.1",
|
|
105
|
+
"helmet": "^8.3.0",
|
|
106
106
|
"html-minifier-terser": "^7.2.0",
|
|
107
107
|
"http-proxy-middleware": "^4.2.0",
|
|
108
108
|
"ignore-walk": "^9.0.0",
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
"json-colorizer": "^3.0.1",
|
|
111
111
|
"jsonwebtoken": "^9.0.3",
|
|
112
112
|
"mariadb": "^3.5.3",
|
|
113
|
-
"marked": "^18.0.
|
|
113
|
+
"marked": "^18.0.6",
|
|
114
114
|
"mocha": "^11.7.6",
|
|
115
|
-
"mongoose": "^9.7.
|
|
115
|
+
"mongoose": "^9.7.4",
|
|
116
116
|
"morgan": "^1.11.0",
|
|
117
117
|
"nodemailer": "^9.0.3",
|
|
118
118
|
"nodemon": "^3.0.1",
|
package/scripts/test-monitor.sh
CHANGED
|
@@ -24,7 +24,7 @@ MODE=runtime # runtime | instance
|
|
|
24
24
|
ENV=development # development | production
|
|
25
25
|
DEPLOY_ID=dd-test # deploy id (instance mode: parent of conf.instances.json)
|
|
26
26
|
INSTANCE_IDS= # instance mode: csv of ids (default: all in conf.instances.json)
|
|
27
|
-
IMAGE=underpost/wp:v3.2.
|
|
27
|
+
IMAGE=underpost/wp:v3.2.80 # runtime mode image (instance mode reads image from conf)
|
|
28
28
|
VERSIONS=green # csv of blue/green versions
|
|
29
29
|
REPLICAS=1 # replicas per deployment
|
|
30
30
|
NAMESPACE=default # k8s namespace
|
|
@@ -1,69 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildCrudController, serviceHandler } from '../../server/middlewares.js';
|
|
2
2
|
import { CoreService } from './core.service.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
static post = async (req, res, options) => {
|
|
8
|
-
try {
|
|
9
|
-
const result = await CoreService.post(req, res, options);
|
|
10
|
-
return res.status(200).json({
|
|
11
|
-
status: 'success',
|
|
12
|
-
data: result,
|
|
13
|
-
});
|
|
14
|
-
} catch (error) {
|
|
15
|
-
logger.error(error, error.stack);
|
|
16
|
-
return res.status(400).json({
|
|
17
|
-
status: 'error',
|
|
18
|
-
message: error.message,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
static get = async (req, res, options) => {
|
|
23
|
-
try {
|
|
24
|
-
const result = await CoreService.put(req, res, options);
|
|
25
|
-
return res.status(200).json({
|
|
26
|
-
status: 'success',
|
|
27
|
-
data: result,
|
|
28
|
-
});
|
|
29
|
-
} catch (error) {
|
|
30
|
-
logger.error(error, error.stack);
|
|
31
|
-
return res.status(400).json({
|
|
32
|
-
status: 'error',
|
|
33
|
-
message: error.message,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
static put = async (req, res, options) => {
|
|
38
|
-
try {
|
|
39
|
-
const result = await CoreService.get(req, res, options);
|
|
40
|
-
return res.status(200).json({
|
|
41
|
-
status: 'success',
|
|
42
|
-
data: result,
|
|
43
|
-
});
|
|
44
|
-
} catch (error) {
|
|
45
|
-
logger.error(error, error.stack);
|
|
46
|
-
return res.status(400).json({
|
|
47
|
-
status: 'error',
|
|
48
|
-
message: error.message,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
static delete = async (req, res, options) => {
|
|
53
|
-
try {
|
|
54
|
-
const result = await CoreService.delete(req, res, options);
|
|
55
|
-
return res.status(200).json({
|
|
56
|
-
status: 'success',
|
|
57
|
-
data: result,
|
|
58
|
-
});
|
|
59
|
-
} catch (error) {
|
|
60
|
-
logger.error(error, error.stack);
|
|
61
|
-
return res.status(400).json({
|
|
62
|
-
status: 'error',
|
|
63
|
-
message: error.message,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
4
|
+
const CoreController = buildCrudController(CoreService, {
|
|
5
|
+
get: serviceHandler(CoreService.get),
|
|
6
|
+
});
|
|
68
7
|
|
|
69
8
|
export { CoreController };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { registerCrudRoutes } from '../../server/middlewares.js';
|
|
1
3
|
import { adminGuard } from '../../server/auth.js';
|
|
2
|
-
import { loggerFactory } from '../../server/logger.js';
|
|
3
4
|
import { CoreController } from './core.controller.js';
|
|
4
|
-
import express from 'express';
|
|
5
|
-
|
|
6
|
-
const logger = loggerFactory(import.meta);
|
|
7
5
|
|
|
8
6
|
class CoreRouter {
|
|
9
7
|
/**
|
|
@@ -11,16 +9,12 @@ class CoreRouter {
|
|
|
11
9
|
* @returns {import('express').Router}
|
|
12
10
|
*/
|
|
13
11
|
static router(options) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
router.put(`/`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.put(req, res, options));
|
|
21
|
-
router.delete(`/:id`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.delete(req, res, options));
|
|
22
|
-
router.delete(`/`, options.authMiddleware, adminGuard, async (req, res) => await CoreController.delete(req, res, options));
|
|
23
|
-
return router;
|
|
12
|
+
const adminOnly = [options.authMiddleware, adminGuard];
|
|
13
|
+
return registerCrudRoutes(express.Router(), CoreController, options, {
|
|
14
|
+
readGuards: adminOnly,
|
|
15
|
+
writeGuards: adminOnly,
|
|
16
|
+
deleteAllGuards: adminOnly,
|
|
17
|
+
});
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
|
|
@@ -1,74 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildCrudController } from '../../server/middlewares.js';
|
|
2
2
|
import { DefaultService } from './default.service.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class DefaultController {
|
|
7
|
-
static post = async (req, res, options) => {
|
|
8
|
-
try {
|
|
9
|
-
const result = await DefaultService.post(req, res, options);
|
|
10
|
-
return res.status(200).json({
|
|
11
|
-
status: 'success',
|
|
12
|
-
data: result,
|
|
13
|
-
});
|
|
14
|
-
} catch (error) {
|
|
15
|
-
logger.error(error, error.stack);
|
|
16
|
-
return res.status(400).json({
|
|
17
|
-
status: 'error',
|
|
18
|
-
message: error.message,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
static get = async (req, res, options) => {
|
|
23
|
-
try {
|
|
24
|
-
const { page, limit } = req.query;
|
|
25
|
-
const result = await DefaultService.get(
|
|
26
|
-
{ ...req, query: { ...req.query, page: parseInt(page), limit: parseInt(limit) } },
|
|
27
|
-
res,
|
|
28
|
-
options,
|
|
29
|
-
);
|
|
30
|
-
return res.status(200).json({
|
|
31
|
-
status: 'success',
|
|
32
|
-
data: result,
|
|
33
|
-
});
|
|
34
|
-
} catch (error) {
|
|
35
|
-
logger.error(error, error.stack);
|
|
36
|
-
return res.status(400).json({
|
|
37
|
-
status: 'error',
|
|
38
|
-
message: error.message,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
static put = async (req, res, options) => {
|
|
43
|
-
try {
|
|
44
|
-
const result = await DefaultService.put(req, res, options);
|
|
45
|
-
return res.status(200).json({
|
|
46
|
-
status: 'success',
|
|
47
|
-
data: result,
|
|
48
|
-
});
|
|
49
|
-
} catch (error) {
|
|
50
|
-
logger.error(error, error.stack);
|
|
51
|
-
return res.status(400).json({
|
|
52
|
-
status: 'error',
|
|
53
|
-
message: error.message,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
static delete = async (req, res, options) => {
|
|
58
|
-
try {
|
|
59
|
-
const result = await DefaultService.delete(req, res, options);
|
|
60
|
-
return res.status(200).json({
|
|
61
|
-
status: 'success',
|
|
62
|
-
data: result,
|
|
63
|
-
});
|
|
64
|
-
} catch (error) {
|
|
65
|
-
logger.error(error, error.stack);
|
|
66
|
-
return res.status(400).json({
|
|
67
|
-
status: 'error',
|
|
68
|
-
message: error.message,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
4
|
+
const DefaultController = buildCrudController(DefaultService);
|
|
73
5
|
|
|
74
6
|
export { DefaultController };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
-
import { DefaultController } from './default.controller.js';
|
|
3
1
|
import express from 'express';
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { registerCrudRoutes } from '../../server/middlewares.js';
|
|
3
|
+
import { DefaultController } from './default.controller.js';
|
|
6
4
|
|
|
7
5
|
class DefaultRouter {
|
|
8
6
|
/**
|
|
@@ -10,19 +8,11 @@ class DefaultRouter {
|
|
|
10
8
|
* @returns {import('express').Router}
|
|
11
9
|
*/
|
|
12
10
|
static router(options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
async (req, res) => await DefaultController.get(req, res, options),
|
|
19
|
-
);
|
|
20
|
-
router.get(`/`, async (req, res) => await DefaultController.get(req, res, options));
|
|
21
|
-
router.put(`/:id`, async (req, res) => await DefaultController.put(req, res, options));
|
|
22
|
-
router.put(`/`, async (req, res) => await DefaultController.put(req, res, options));
|
|
23
|
-
router.delete(`/:id`, async (req, res) => await DefaultController.delete(req, res, options));
|
|
24
|
-
router.delete(`/`, async (req, res) => await DefaultController.delete(req, res, options));
|
|
25
|
-
return router;
|
|
11
|
+
// Fully unguarded (matches prior behavior).
|
|
12
|
+
return registerCrudRoutes(express.Router(), DefaultController, options, {
|
|
13
|
+
writeGuards: [],
|
|
14
|
+
deleteAllGuards: [],
|
|
15
|
+
});
|
|
26
16
|
}
|
|
27
17
|
}
|
|
28
18
|
|
|
@@ -1,81 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildCrudController, serviceHandler } from '../../server/middlewares.js';
|
|
2
2
|
import { DocumentService } from './document.service.js';
|
|
3
|
-
const logger = loggerFactory(import.meta);
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
status: 'success',
|
|
10
|
-
data: await DocumentService.post(req, res, options),
|
|
11
|
-
});
|
|
12
|
-
} catch (error) {
|
|
13
|
-
logger.error(error, error.stack);
|
|
14
|
-
return res.status(400).json({
|
|
15
|
-
status: 'error',
|
|
16
|
-
message: error.message,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
static get = async (req, res, options) => {
|
|
21
|
-
try {
|
|
22
|
-
return res.status(200).json({
|
|
23
|
-
status: 'success',
|
|
24
|
-
data: await DocumentService.get(req, res, options),
|
|
25
|
-
});
|
|
26
|
-
} catch (error) {
|
|
27
|
-
logger.error(error, error.stack);
|
|
28
|
-
return res.status(400).json({
|
|
29
|
-
status: 'error',
|
|
30
|
-
message: error.message,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
static delete = async (req, res, options) => {
|
|
35
|
-
try {
|
|
36
|
-
const result = await DocumentService.delete(req, res, options);
|
|
37
|
-
return res.status(200).json({
|
|
38
|
-
status: 'success',
|
|
39
|
-
data: result,
|
|
40
|
-
});
|
|
41
|
-
} catch (error) {
|
|
42
|
-
logger.error(error, error.stack);
|
|
43
|
-
return res.status(400).json({
|
|
44
|
-
status: 'error',
|
|
45
|
-
message: error.message,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
static put = async (req, res, options) => {
|
|
50
|
-
try {
|
|
51
|
-
const result = await DocumentService.put(req, res, options);
|
|
52
|
-
return res.status(200).json({
|
|
53
|
-
status: 'success',
|
|
54
|
-
data: result,
|
|
55
|
-
});
|
|
56
|
-
} catch (error) {
|
|
57
|
-
logger.error(error, error.stack);
|
|
58
|
-
return res.status(400).json({
|
|
59
|
-
status: 'error',
|
|
60
|
-
message: error.message,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
static patch = async (req, res, options) => {
|
|
65
|
-
try {
|
|
66
|
-
const result = await DocumentService.patch(req, res, options);
|
|
67
|
-
return res.status(200).json({
|
|
68
|
-
status: 'success',
|
|
69
|
-
data: result,
|
|
70
|
-
});
|
|
71
|
-
} catch (error) {
|
|
72
|
-
logger.error(error, error.stack);
|
|
73
|
-
return res.status(400).json({
|
|
74
|
-
status: 'error',
|
|
75
|
-
message: error.message,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
4
|
+
const DocumentController = buildCrudController(DocumentService, {
|
|
5
|
+
get: serviceHandler(DocumentService.get),
|
|
6
|
+
patch: serviceHandler(DocumentService.patch),
|
|
7
|
+
});
|
|
80
8
|
|
|
81
9
|
export { DocumentController };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
-
import { DocumentController } from './document.controller.js';
|
|
3
1
|
import express from 'express';
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { registerCrudRoutes } from '../../server/middlewares.js';
|
|
3
|
+
import { DocumentController } from './document.controller.js';
|
|
6
4
|
|
|
7
5
|
class DocumentRouter {
|
|
8
6
|
/**
|
|
@@ -11,23 +9,21 @@ class DocumentRouter {
|
|
|
11
9
|
*/
|
|
12
10
|
static router(options) {
|
|
13
11
|
const router = express.Router();
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const authOnly = [options.authMiddleware];
|
|
13
|
+
// Public listings — must come before the guarded generic /:id routes.
|
|
16
14
|
router.get(`/public/high`, async (req, res) => await DocumentController.get(req, res, options));
|
|
17
15
|
router.get(`/public`, async (req, res) => await DocumentController.get(req, res, options));
|
|
18
|
-
router.get(`/:id`, options.authMiddleware, async (req, res) => await DocumentController.get(req, res, options));
|
|
19
|
-
router.get(`/`, options.authMiddleware, async (req, res) => await DocumentController.get(req, res, options));
|
|
20
|
-
router.put(`/:id`, options.authMiddleware, async (req, res) => await DocumentController.put(req, res, options));
|
|
21
|
-
router.put(`/`, options.authMiddleware, async (req, res) => await DocumentController.put(req, res, options));
|
|
22
16
|
router.patch(`/:id/copy-share-link`, async (req, res) => await DocumentController.patch(req, res, options));
|
|
23
17
|
router.patch(
|
|
24
18
|
`/:id/toggle-public`,
|
|
25
19
|
options.authMiddleware,
|
|
26
20
|
async (req, res) => await DocumentController.patch(req, res, options),
|
|
27
21
|
);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
return registerCrudRoutes(router, DocumentController, options, {
|
|
23
|
+
readGuards: authOnly,
|
|
24
|
+
writeGuards: authOnly,
|
|
25
|
+
deleteAllGuards: authOnly,
|
|
26
|
+
});
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
|
|
@@ -1,59 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { controllerHandler, sendSuccess, serviceHandler, setCrossOriginHeaders } from '../../server/middlewares.js';
|
|
2
2
|
import { FileService } from './file.service.js';
|
|
3
|
-
const logger = loggerFactory(import.meta);
|
|
4
3
|
|
|
5
4
|
class FileController {
|
|
6
|
-
static post =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return res.status(400).json({
|
|
15
|
-
status: 'error',
|
|
16
|
-
message: error.message,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
static get = async (req, res, options) => {
|
|
21
|
-
try {
|
|
22
|
-
if (req && req.headers && req.headers.origin) {
|
|
23
|
-
res.set('Access-Control-Allow-Origin', req.headers.origin);
|
|
24
|
-
} else res.setHeader('Access-Control-Allow-Origin', '*');
|
|
25
|
-
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
|
|
26
|
-
const result = await FileService.get(req, res, options);
|
|
27
|
-
if (result instanceof Buffer) {
|
|
28
|
-
return res.status(200).end(result);
|
|
29
|
-
}
|
|
30
|
-
return res.status(200).json({
|
|
31
|
-
status: 'success',
|
|
32
|
-
data: result,
|
|
33
|
-
});
|
|
34
|
-
} catch (error) {
|
|
35
|
-
logger.error(error, error.stack);
|
|
36
|
-
return res.status(400).json({
|
|
37
|
-
status: 'error',
|
|
38
|
-
message: error.message,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
static delete = async (req, res, options) => {
|
|
43
|
-
try {
|
|
44
|
-
const result = await FileService.delete(req, res, options);
|
|
45
|
-
return res.status(200).json({
|
|
46
|
-
status: 'success',
|
|
47
|
-
data: result,
|
|
48
|
-
});
|
|
49
|
-
} catch (error) {
|
|
50
|
-
logger.error(error, error.stack);
|
|
51
|
-
return res.status(400).json({
|
|
52
|
-
status: 'error',
|
|
53
|
-
message: error.message,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
5
|
+
static post = serviceHandler(FileService.post);
|
|
6
|
+
static get = controllerHandler(async (req, res, options) => {
|
|
7
|
+
setCrossOriginHeaders(req, res);
|
|
8
|
+
const result = await FileService.get(req, res, options);
|
|
9
|
+
if (result instanceof Buffer) return res.status(200).end(result);
|
|
10
|
+
return sendSuccess(res, result);
|
|
11
|
+
});
|
|
12
|
+
static delete = serviceHandler(FileService.delete);
|
|
57
13
|
}
|
|
58
14
|
|
|
59
15
|
export { FileController };
|