@fecommunity/reactpress 3.0.0 → 3.0.2
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/README.md +67 -21
- package/bin/reactpress.js +8 -5
- package/dist/index.js +0 -0
- package/lib/api-dev.js +4 -4
- package/lib/bootstrap.js +2 -2
- package/lib/build.js +130 -13
- package/lib/dev.js +2 -14
- package/lib/i18n/strings.js +32 -2
- package/lib/lifecycle.js +8 -8
- package/lib/paths.js +39 -19
- package/lib/pm2.js +2 -2
- package/lib/publish.js +9 -0
- package/lib/root.js +63 -6
- package/lib/spawn.js +15 -10
- package/lib/status.js +1 -1
- package/package.json +7 -4
- package/server/dist/app.module.js +1 -26
- package/server/dist/app.module.js.map +1 -1
- package/server/dist/modules/article/article.controller.d.ts +1 -6
- package/server/dist/modules/article/article.controller.js +1 -45
- package/server/dist/modules/article/article.controller.js.map +1 -1
- package/server/dist/modules/article/article.entity.d.ts +0 -1
- package/server/dist/modules/article/article.entity.js +0 -5
- package/server/dist/modules/article/article.entity.js.map +1 -1
- package/server/dist/modules/article/article.module.js +2 -14
- package/server/dist/modules/article/article.module.js.map +1 -1
- package/server/dist/modules/article/article.service.d.ts +1 -9
- package/server/dist/modules/article/article.service.js +5 -59
- package/server/dist/modules/article/article.service.js.map +1 -1
- package/server/dist/modules/auth/auth.service.js +3 -4
- package/server/dist/modules/auth/auth.service.js.map +1 -1
- package/server/dist/modules/auth/jwt-auth.guard.js +1 -2
- package/server/dist/modules/auth/jwt-auth.guard.js.map +1 -1
- package/server/dist/modules/auth/jwt.strategy.js +1 -2
- package/server/dist/modules/auth/jwt.strategy.js.map +1 -1
- package/server/dist/modules/category/category.service.js +2 -3
- package/server/dist/modules/category/category.service.js.map +1 -1
- package/server/dist/modules/comment/comment.module.js +1 -10
- package/server/dist/modules/comment/comment.module.js.map +1 -1
- package/server/dist/modules/comment/comment.service.d.ts +1 -3
- package/server/dist/modules/comment/comment.service.js +5 -15
- package/server/dist/modules/comment/comment.service.js.map +1 -1
- package/server/dist/modules/knowledge/knowledge.service.js +2 -3
- package/server/dist/modules/knowledge/knowledge.service.js.map +1 -1
- package/server/dist/modules/page/page.service.js +1 -2
- package/server/dist/modules/page/page.service.js.map +1 -1
- package/server/dist/modules/smtp/smtp.service.js +1 -2
- package/server/dist/modules/smtp/smtp.service.js.map +1 -1
- package/server/dist/modules/tag/tag.service.js +2 -3
- package/server/dist/modules/tag/tag.service.js.map +1 -1
- package/server/dist/modules/user/user.controller.js +3 -4
- package/server/dist/modules/user/user.controller.js.map +1 -1
- package/server/dist/modules/user/user.service.js +9 -10
- package/server/dist/modules/user/user.service.js.map +1 -1
- package/server/dist/starter.js +1 -1
- package/server/dist/tsconfig.build.tsbuildinfo +11335 -11537
- package/server/dist/utils/oss.util.js +1 -2
- package/server/dist/utils/oss.util.js.map +1 -1
- package/templates/env.default +1 -1
- package/templates/package.json +3 -2
- package/ui/banner.js +2 -2
- package/ui/interactive.js +20 -4
package/lib/publish.js
CHANGED
|
@@ -389,6 +389,15 @@ function buildPackage(pkg) {
|
|
|
389
389
|
execSync('pnpm run prebuild && pnpm run build', { cwd: path.join(process.cwd(), pkg.path), stdio: 'inherit' });
|
|
390
390
|
} else if (pkg.path === 'toolkit') {
|
|
391
391
|
execSync('pnpm run build', { cwd: path.join(process.cwd(), pkg.path), stdio: 'inherit' });
|
|
392
|
+
} else if (pkg.path === 'cli') {
|
|
393
|
+
execSync('node scripts/sync-bundled-core.mjs', {
|
|
394
|
+
cwd: path.join(process.cwd(), pkg.path),
|
|
395
|
+
stdio: 'inherit',
|
|
396
|
+
});
|
|
397
|
+
execSync('node scripts/install-bundled-runtime.mjs', {
|
|
398
|
+
cwd: path.join(process.cwd(), pkg.path),
|
|
399
|
+
stdio: 'inherit',
|
|
400
|
+
});
|
|
392
401
|
} else if (pkg.path === 'templates/hello-world' || pkg.path === 'templates/twentytwentyfive') {
|
|
393
402
|
// Templates don't need to be built, just validate package.json
|
|
394
403
|
console.log(chalk.gray(' Templates do not require building, skipping...'));
|
package/lib/root.js
CHANGED
|
@@ -1,13 +1,66 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const CLI_PACKAGE_NAME = '@fecommunity/reactpress';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Install root: monorepo checkout (repo root) or published @fecommunity/reactpress package root.
|
|
8
|
+
* cli/lib -> ../.. when pnpm-workspace.yaml exists; published lib/ -> .. only.
|
|
9
|
+
*/
|
|
5
10
|
function getMonorepoRoot() {
|
|
6
|
-
|
|
11
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
12
|
+
const parentOfPackage = path.resolve(__dirname, '../..');
|
|
13
|
+
if (fs.existsSync(path.join(parentOfPackage, 'pnpm-workspace.yaml'))) {
|
|
14
|
+
return parentOfPackage;
|
|
15
|
+
}
|
|
16
|
+
return packageRoot;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isPublishedCliRoot(dir) {
|
|
20
|
+
const resolved = path.resolve(dir);
|
|
21
|
+
try {
|
|
22
|
+
const pkg = JSON.parse(
|
|
23
|
+
fs.readFileSync(path.join(resolved, 'package.json'), 'utf8')
|
|
24
|
+
);
|
|
25
|
+
if (pkg.name !== CLI_PACKAGE_NAME) return false;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return !fs.existsSync(path.join(resolved, 'pnpm-workspace.yaml'));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isProjectRoot(dir) {
|
|
33
|
+
const resolved = path.resolve(dir);
|
|
34
|
+
if (isPublishedCliRoot(resolved)) return false;
|
|
35
|
+
return (
|
|
36
|
+
fs.existsSync(path.join(resolved, '.reactpress', 'config.json')) ||
|
|
37
|
+
fs.existsSync(path.join(resolved, 'pnpm-workspace.yaml')) ||
|
|
38
|
+
fs.existsSync(path.join(resolved, 'server', 'src', 'main.ts')) ||
|
|
39
|
+
fs.existsSync(path.join(resolved, 'toolkit', 'package.json'))
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function findProjectRoot(startDir = process.cwd()) {
|
|
44
|
+
let dir = path.resolve(startDir);
|
|
45
|
+
while (true) {
|
|
46
|
+
if (isProjectRoot(dir)) return dir;
|
|
47
|
+
const parent = path.dirname(dir);
|
|
48
|
+
if (parent === dir) break;
|
|
49
|
+
dir = parent;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
7
52
|
}
|
|
8
53
|
|
|
9
54
|
function getProjectRoot() {
|
|
10
|
-
|
|
55
|
+
const envRoot = process.env.REACTPRESS_ORIGINAL_CWD;
|
|
56
|
+
if (envRoot) {
|
|
57
|
+
const resolved = path.resolve(envRoot);
|
|
58
|
+
if (isProjectRoot(resolved)) return resolved;
|
|
59
|
+
}
|
|
60
|
+
const discovered = findProjectRoot(process.cwd());
|
|
61
|
+
if (discovered) return discovered;
|
|
62
|
+
if (envRoot) return path.resolve(envRoot);
|
|
63
|
+
return path.resolve(process.cwd());
|
|
11
64
|
}
|
|
12
65
|
|
|
13
66
|
function ensureOriginalCwd() {
|
|
@@ -16,10 +69,11 @@ function ensureOriginalCwd() {
|
|
|
16
69
|
return root;
|
|
17
70
|
}
|
|
18
71
|
|
|
19
|
-
function isMonorepoCheckout(cwd
|
|
72
|
+
function isMonorepoCheckout(cwd) {
|
|
73
|
+
const resolved = path.resolve(cwd || process.cwd());
|
|
20
74
|
return (
|
|
21
|
-
fs.existsSync(path.join(
|
|
22
|
-
fs.existsSync(path.join(
|
|
75
|
+
fs.existsSync(path.join(resolved, 'pnpm-workspace.yaml')) ||
|
|
76
|
+
fs.existsSync(path.join(resolved, 'server', 'src', 'main.ts'))
|
|
23
77
|
);
|
|
24
78
|
}
|
|
25
79
|
|
|
@@ -28,4 +82,7 @@ module.exports = {
|
|
|
28
82
|
getProjectRoot,
|
|
29
83
|
ensureOriginalCwd,
|
|
30
84
|
isMonorepoCheckout,
|
|
85
|
+
isProjectRoot,
|
|
86
|
+
findProjectRoot,
|
|
87
|
+
isPublishedCliRoot,
|
|
31
88
|
};
|
package/lib/spawn.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
const { spawn, spawnSync } = require('child_process');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
-
const {
|
|
4
|
+
const { ensureOriginalCwd } = require('./root');
|
|
5
5
|
const { getCliPackageRoot } = require('./paths');
|
|
6
6
|
const { t, resolveLocale } = require('./i18n');
|
|
7
7
|
|
|
8
|
+
function resolveSpawnCwd(options = {}) {
|
|
9
|
+
return options.cwd ? path.resolve(options.cwd) : ensureOriginalCwd();
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
function runSync(command, args, options = {}) {
|
|
13
|
+
const cwd = resolveSpawnCwd(options);
|
|
9
14
|
const result = spawnSync(command, args, {
|
|
10
|
-
cwd
|
|
15
|
+
cwd,
|
|
11
16
|
stdio: 'inherit',
|
|
12
17
|
env: {
|
|
13
18
|
...process.env,
|
|
14
19
|
REACTPRESS_LANG: process.env.REACTPRESS_LANG || resolveLocale(),
|
|
15
|
-
REACTPRESS_ORIGINAL_CWD:
|
|
16
|
-
|
|
20
|
+
REACTPRESS_ORIGINAL_CWD: cwd,
|
|
21
|
+
...options.env,
|
|
17
22
|
},
|
|
18
23
|
shell: options.shell ?? false,
|
|
19
24
|
});
|
|
@@ -28,15 +33,15 @@ function runSync(command, args, options = {}) {
|
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
function runNodeScript(scriptPath, args = [], options = {}) {
|
|
36
|
+
const cwd = resolveSpawnCwd(options);
|
|
31
37
|
return new Promise((resolve, reject) => {
|
|
32
38
|
const child = spawn(process.execPath, [scriptPath, ...args], {
|
|
33
39
|
stdio: 'inherit',
|
|
34
|
-
cwd
|
|
40
|
+
cwd,
|
|
35
41
|
env: {
|
|
36
42
|
...process.env,
|
|
37
43
|
REACTPRESS_LANG: process.env.REACTPRESS_LANG || resolveLocale(),
|
|
38
|
-
REACTPRESS_ORIGINAL_CWD:
|
|
39
|
-
options.cwd || process.env.REACTPRESS_ORIGINAL_CWD || process.cwd(),
|
|
44
|
+
REACTPRESS_ORIGINAL_CWD: cwd,
|
|
40
45
|
...options.env,
|
|
41
46
|
},
|
|
42
47
|
});
|
|
@@ -57,15 +62,15 @@ function runNodeScript(scriptPath, args = [], options = {}) {
|
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
function spawnDetached(scriptPath, args = [], options = {}) {
|
|
65
|
+
const cwd = resolveSpawnCwd(options);
|
|
60
66
|
const child = spawn(process.execPath, [scriptPath, ...args], {
|
|
61
67
|
stdio: options.stdio ?? 'ignore',
|
|
62
68
|
detached: true,
|
|
63
|
-
cwd
|
|
69
|
+
cwd,
|
|
64
70
|
env: {
|
|
65
71
|
...process.env,
|
|
66
72
|
REACTPRESS_LANG: process.env.REACTPRESS_LANG || resolveLocale(),
|
|
67
|
-
REACTPRESS_ORIGINAL_CWD:
|
|
68
|
-
options.cwd || process.env.REACTPRESS_ORIGINAL_CWD || process.cwd(),
|
|
73
|
+
REACTPRESS_ORIGINAL_CWD: cwd,
|
|
69
74
|
...options.env,
|
|
70
75
|
},
|
|
71
76
|
});
|
package/lib/status.js
CHANGED
|
@@ -37,7 +37,7 @@ async function printUnifiedStatus(projectRoot = ensureOriginalCwd()) {
|
|
|
37
37
|
checkHealth(healthUrl),
|
|
38
38
|
]);
|
|
39
39
|
|
|
40
|
-
const apiSource = isUsingMonorepoServer()
|
|
40
|
+
const apiSource = isUsingMonorepoServer(projectRoot)
|
|
41
41
|
? t('status.apiSource.monorepo')
|
|
42
42
|
: t('status.apiSource.bundle');
|
|
43
43
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fecommunity/reactpress",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "ReactPress 3.0 — zero-config CMS: one package, one reactpress command",
|
|
5
5
|
"author": "fecommunity",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"README.md",
|
|
35
35
|
"LICENSE"
|
|
36
36
|
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"prepare": "node scripts/sync-bundled-core.mjs",
|
|
39
|
+
"prepack": "node scripts/sync-bundled-core.mjs"
|
|
40
|
+
},
|
|
37
41
|
"publishConfig": {
|
|
38
42
|
"access": "public",
|
|
39
43
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -53,6 +57,5 @@
|
|
|
53
57
|
},
|
|
54
58
|
"devDependencies": {
|
|
55
59
|
"@fecommunity/reactpress-cli-core": "npm:@fecommunity/reactpress-cli@0.1.0"
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -36,12 +36,6 @@ const user_entity_1 = require("./modules/user/user.entity");
|
|
|
36
36
|
const user_module_1 = require("./modules/user/user.module");
|
|
37
37
|
const view_entity_1 = require("./modules/view/view.entity");
|
|
38
38
|
const view_module_1 = require("./modules/view/view.module");
|
|
39
|
-
const api_key_entity_1 = require("./modules/api-key/api-key.entity");
|
|
40
|
-
const api_key_module_1 = require("./modules/api-key/api-key.module");
|
|
41
|
-
const article_revision_entity_1 = require("./modules/article/article-revision.entity");
|
|
42
|
-
const health_module_1 = require("./modules/health/health.module");
|
|
43
|
-
const webhook_entity_1 = require("./modules/webhook/webhook.entity");
|
|
44
|
-
const webhook_module_1 = require("./modules/webhook/webhook.module");
|
|
45
39
|
let AppModule = class AppModule {
|
|
46
40
|
};
|
|
47
41
|
AppModule = __decorate([
|
|
@@ -53,23 +47,7 @@ AppModule = __decorate([
|
|
|
53
47
|
inject: [config_1.ConfigService],
|
|
54
48
|
useFactory: async (configService) => ({
|
|
55
49
|
type: 'mysql',
|
|
56
|
-
entities: [
|
|
57
|
-
user_entity_1.User,
|
|
58
|
-
file_entity_1.File,
|
|
59
|
-
knowledge_entity_1.Knowledge,
|
|
60
|
-
article_entity_1.Article,
|
|
61
|
-
article_revision_entity_1.ArticleRevision,
|
|
62
|
-
category_entity_1.Category,
|
|
63
|
-
tag_entity_1.Tag,
|
|
64
|
-
comment_entity_1.Comment,
|
|
65
|
-
setting_entity_1.Setting,
|
|
66
|
-
smtp_entity_1.SMTP,
|
|
67
|
-
page_entity_1.Page,
|
|
68
|
-
view_entity_1.View,
|
|
69
|
-
search_entity_1.Search,
|
|
70
|
-
api_key_entity_1.ApiKey,
|
|
71
|
-
webhook_entity_1.Webhook,
|
|
72
|
-
],
|
|
50
|
+
entities: [user_entity_1.User, file_entity_1.File, knowledge_entity_1.Knowledge, article_entity_1.Article, category_entity_1.Category, tag_entity_1.Tag, comment_entity_1.Comment, setting_entity_1.Setting, smtp_entity_1.SMTP, page_entity_1.Page, view_entity_1.View, search_entity_1.Search],
|
|
73
51
|
host: configService.get('DB_HOST', '0.0.0.0'),
|
|
74
52
|
port: configService.get('DB_PORT', 3306),
|
|
75
53
|
username: configService.get('DB_USER', 'root'),
|
|
@@ -93,9 +71,6 @@ AppModule = __decorate([
|
|
|
93
71
|
page_module_1.PageModule,
|
|
94
72
|
view_module_1.ViewModule,
|
|
95
73
|
search_module_1.SearchModule,
|
|
96
|
-
health_module_1.HealthModule,
|
|
97
|
-
api_key_module_1.ApiKeyModule,
|
|
98
|
-
webhook_module_1.WebhookModule,
|
|
99
74
|
],
|
|
100
75
|
controllers: [],
|
|
101
76
|
providers: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AACA,2DAAyD;AACzD,2CAAwC;AACxC,2CAA6D;AAC7D,6CAAgD;AAEhD,qEAA2D;AAE3D,qEAAiE;AAEjE,4DAAwD;AACxD,wEAA8D;AAE9D,wEAAoE;AACpE,qEAA2D;AAE3D,qE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AAE,kBAAI,EAAE,4BAAS,EAAE,wBAAO,EAAE,0BAAQ,EAAE,gBAAG,EAAE,wBAAO,EAAE,wBAAO,EAAE,kBAAI,EAAE,kBAAI,EAAE,kBAAI,EAAE,sBAAM,CAAC;oBACrG,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC;oBAC7C,IAAI,EAAE,aAAa,CAAC,GAAG,CAAS,SAAS,EAAE,IAAI,CAAC;oBAChD,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC;oBAC9C,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC;oBAChD,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,aAAa,EAAE,YAAY,CAAC;oBACxD,OAAO,EAAE,SAAS;oBAClB,QAAQ,EAAE,QAAQ;oBAClB,WAAW,EAAE,IAAI;iBAClB,CAAC;aACH,CAAC;YACF,wBAAU;YACV,wBAAU;YACV,sBAAS;YACT,8BAAa;YACb,kCAAe;YACf,gCAAc;YACd,8BAAa;YACb,8BAAa;YACb,wBAAU;YACV,wBAAU;YACV,wBAAU;YACV,wBAAU;YACV,4BAAY;SACb;QACD,WAAW,EAAE,EAAE;QACf,SAAS,EAAE,EAAE;KACd,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { JwtService } from '@nestjs/jwt';
|
|
2
|
-
import { ApiKeyService } from '../api-key/api-key.service';
|
|
3
2
|
import { UserService } from '../user/user.service';
|
|
4
3
|
import { Article } from './article.entity';
|
|
5
4
|
import { ArticleService } from './article.service';
|
|
6
5
|
export declare class ArticleController {
|
|
7
6
|
private readonly articleService;
|
|
8
|
-
private readonly apiKeyService;
|
|
9
7
|
private readonly jwtService;
|
|
10
8
|
private readonly userService;
|
|
11
|
-
constructor(articleService: ArticleService,
|
|
9
|
+
constructor(articleService: ArticleService, jwtService: JwtService, userService: UserService);
|
|
12
10
|
create(article: any): Promise<Article>;
|
|
13
11
|
findAll(queryParams: any): Promise<[Article[], number]>;
|
|
14
|
-
findHeadless(req: any, queryParams: any): Promise<[Article[], number]>;
|
|
15
|
-
listRevisions(id: string): Promise<import("./article-revision.entity").ArticleRevision[]>;
|
|
16
|
-
restoreRevision(id: string, revisionId: string): Promise<Article>;
|
|
17
12
|
findArticlesByCategory(category: any, queryParams: any): Promise<(number | Article[])[]>;
|
|
18
13
|
findArticlesByTag(tag: any, queryParams: any): Promise<(number | Article[])[]>;
|
|
19
14
|
getRecommendArticles(): Promise<Article[]>;
|
|
@@ -13,21 +13,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ArticleController = void 0;
|
|
16
|
-
const api_messages_1 = require("../../common/api-messages");
|
|
17
16
|
const common_1 = require("@nestjs/common");
|
|
18
17
|
const jwt_1 = require("@nestjs/jwt");
|
|
19
18
|
const swagger_1 = require("@nestjs/swagger");
|
|
20
|
-
const api_key_guard_1 = require("../api-key/api-key.guard");
|
|
21
|
-
const api_key_service_1 = require("../api-key/api-key.service");
|
|
22
19
|
const jwt_auth_guard_1 = require("../auth/jwt-auth.guard");
|
|
23
20
|
const roles_guard_1 = require("../auth/roles.guard");
|
|
24
21
|
const user_service_1 = require("../user/user.service");
|
|
25
22
|
const article_entity_1 = require("./article.entity");
|
|
26
23
|
const article_service_1 = require("./article.service");
|
|
27
24
|
let ArticleController = class ArticleController {
|
|
28
|
-
constructor(articleService,
|
|
25
|
+
constructor(articleService, jwtService, userService) {
|
|
29
26
|
this.articleService = articleService;
|
|
30
|
-
this.apiKeyService = apiKeyService;
|
|
31
27
|
this.jwtService = jwtService;
|
|
32
28
|
this.userService = userService;
|
|
33
29
|
}
|
|
@@ -37,18 +33,6 @@ let ArticleController = class ArticleController {
|
|
|
37
33
|
findAll(queryParams) {
|
|
38
34
|
return this.articleService.findAll(queryParams);
|
|
39
35
|
}
|
|
40
|
-
findHeadless(req, queryParams) {
|
|
41
|
-
if (!this.apiKeyService.hasScope(req.apiKey, 'read')) {
|
|
42
|
-
throw new common_1.ForbiddenException(api_messages_1.ApiMsg.API_KEY_MISSING_READ);
|
|
43
|
-
}
|
|
44
|
-
return this.articleService.findAll(Object.assign(Object.assign({}, queryParams), { status: 'publish' }));
|
|
45
|
-
}
|
|
46
|
-
listRevisions(id) {
|
|
47
|
-
return this.articleService.listRevisions(id);
|
|
48
|
-
}
|
|
49
|
-
restoreRevision(id, revisionId) {
|
|
50
|
-
return this.articleService.restoreRevision(id, revisionId);
|
|
51
|
-
}
|
|
52
36
|
findArticlesByCategory(category, queryParams) {
|
|
53
37
|
return this.articleService.findArticlesByCategory(category, queryParams);
|
|
54
38
|
}
|
|
@@ -114,33 +98,6 @@ __decorate([
|
|
|
114
98
|
__metadata("design:paramtypes", [Object]),
|
|
115
99
|
__metadata("design:returntype", void 0)
|
|
116
100
|
], ArticleController.prototype, "findAll", null);
|
|
117
|
-
__decorate([
|
|
118
|
-
common_1.Get('headless/list'),
|
|
119
|
-
common_1.UseGuards(api_key_guard_1.ApiKeyGuard),
|
|
120
|
-
common_1.HttpCode(common_1.HttpStatus.OK),
|
|
121
|
-
__param(0, common_1.Request()), __param(1, common_1.Query()),
|
|
122
|
-
__metadata("design:type", Function),
|
|
123
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
124
|
-
__metadata("design:returntype", void 0)
|
|
125
|
-
], ArticleController.prototype, "findHeadless", null);
|
|
126
|
-
__decorate([
|
|
127
|
-
common_1.Get(':id/revisions'),
|
|
128
|
-
roles_guard_1.Roles('admin'),
|
|
129
|
-
common_1.UseGuards(jwt_auth_guard_1.JwtAuthGuard),
|
|
130
|
-
__param(0, common_1.Param('id')),
|
|
131
|
-
__metadata("design:type", Function),
|
|
132
|
-
__metadata("design:paramtypes", [String]),
|
|
133
|
-
__metadata("design:returntype", void 0)
|
|
134
|
-
], ArticleController.prototype, "listRevisions", null);
|
|
135
|
-
__decorate([
|
|
136
|
-
common_1.Post(':id/revisions/:revisionId/restore'),
|
|
137
|
-
roles_guard_1.Roles('admin'),
|
|
138
|
-
common_1.UseGuards(jwt_auth_guard_1.JwtAuthGuard),
|
|
139
|
-
__param(0, common_1.Param('id')), __param(1, common_1.Param('revisionId')),
|
|
140
|
-
__metadata("design:type", Function),
|
|
141
|
-
__metadata("design:paramtypes", [String, String]),
|
|
142
|
-
__metadata("design:returntype", void 0)
|
|
143
|
-
], ArticleController.prototype, "restoreRevision", null);
|
|
144
101
|
__decorate([
|
|
145
102
|
common_1.Get('/category/:id'),
|
|
146
103
|
common_1.HttpCode(common_1.HttpStatus.OK),
|
|
@@ -234,7 +191,6 @@ ArticleController = __decorate([
|
|
|
234
191
|
common_1.Controller('article'),
|
|
235
192
|
common_1.UseGuards(roles_guard_1.RolesGuard),
|
|
236
193
|
__metadata("design:paramtypes", [article_service_1.ArticleService,
|
|
237
|
-
api_key_service_1.ApiKeyService,
|
|
238
194
|
jwt_1.JwtService,
|
|
239
195
|
user_service_1.UserService])
|
|
240
196
|
], ArticleController);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"article.controller.js","sourceRoot":"","sources":["../../../src/modules/article/article.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"article.controller.js","sourceRoot":"","sources":["../../../src/modules/article/article.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAawB;AACxB,qCAAyC;AACzC,6CAAuD;AAEvD,2DAAsD;AACtD,qDAAwD;AAExD,uDAAmD;AACnD,qDAA2C;AAC3C,uDAAmD;AAKnD,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAC5B,YACmB,cAA8B,EAE9B,UAAsB,EACtB,WAAwB;QAHxB,mBAAc,GAAd,cAAc,CAAgB;QAE9B,eAAU,GAAV,UAAU,CAAY;QACtB,gBAA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P,WAAA,cAAK,CAAC,IAAI,CAAC,CAAA,EAAM,WAAA,aAAI,CAAC,MAAM,CAAC,CAAA;;;;wDAE7C;AAWD;IAJC,cAAK,CAAC,KAAK,CAAC;IACZ,mBAAK,CAAC,OAAO,CAAC;IACd,kBAAS,CAAC,6BAAY,CAAC;IACvB,iBAAQ,CAAC,mBAAU,CAAC,EAAE,CAAC;IACZ,WAAA,cAAK,CAAC,IAAI,CAAC,CAAA,EAAM,WAAA,aAAI,EAAE,CAAA;;;;mDAElC;AASD;IAHC,eAAM,CAAC,KAAK,CAAC;IACb,mBAAK,CAAC,OAAO,CAAC;IACd,kBAAS,CAAC,6BAAY,CAAC;IACZ,WAAA,cAAK,CAAC,IAAI,CAAC,CAAA;;;;mDAEtB;AArJU,iBAAiB;IAH7B,iBAAO,CAAC,SAAS,CAAC;IAClB,mBAAU,CAAC,SAAS,CAAC;IACrB,kBAAS,CAAC,wBAAU,CAAC;qCAGe,gCAAc;QAElB,gBAAU;QACT,0BAAW;GALhC,iBAAiB,CAsJ7B;AAtJY,8CAAiB"}
|
|
@@ -103,11 +103,6 @@ __decorate([
|
|
|
103
103
|
typeorm_1.Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }),
|
|
104
104
|
__metadata("design:type", Date)
|
|
105
105
|
], Article.prototype, "publishAt", void 0);
|
|
106
|
-
__decorate([
|
|
107
|
-
swagger_1.ApiProperty({ description: '定时发布时间(草稿状态下生效)' }),
|
|
108
|
-
typeorm_1.Column({ type: 'timestamp', nullable: true }),
|
|
109
|
-
__metadata("design:type", Date)
|
|
110
|
-
], Article.prototype, "scheduledPublishAt", void 0);
|
|
111
106
|
__decorate([
|
|
112
107
|
swagger_1.ApiProperty(),
|
|
113
108
|
typeorm_1.CreateDateColumn({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"article.entity.js","sourceRoot":"","sources":["../../../src/modules/article/article.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AA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AM;QACf,IAAI,EAAE,WAAW;KAClB,CAAC;8BACQ,IAAI;yCAAC;AAQf;IANC,qBAAW,EAAE;IACb,0BAAgB,CAAC;QAChB,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,WAAW;KAClB,CAAC;8BACQ,IAAI;yCAAC;AArFJ,OAAO;IADnB,gBAAM,EAAE;GACI,OAAO,CAsFnB;AAtFY,0BAAO"}
|
|
@@ -9,32 +9,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.ArticleModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
12
|
-
const api_key_module_1 = require("../api-key/api-key.module");
|
|
13
12
|
const auth_module_1 = require("../auth/auth.module");
|
|
14
13
|
const category_module_1 = require("../category/category.module");
|
|
15
14
|
const tag_module_1 = require("../tag/tag.module");
|
|
16
15
|
const user_module_1 = require("../user/user.module");
|
|
17
|
-
const webhook_module_1 = require("../webhook/webhook.module");
|
|
18
|
-
const article_revision_entity_1 = require("./article-revision.entity");
|
|
19
16
|
const article_controller_1 = require("./article.controller");
|
|
20
17
|
const article_entity_1 = require("./article.entity");
|
|
21
18
|
const article_service_1 = require("./article.service");
|
|
22
|
-
const scheduled_publish_service_1 = require("./scheduled-publish.service");
|
|
23
19
|
let ArticleModule = class ArticleModule {
|
|
24
20
|
};
|
|
25
21
|
ArticleModule = __decorate([
|
|
26
22
|
common_1.Module({
|
|
27
|
-
imports: [
|
|
28
|
-
typeorm_1.TypeOrmModule.forFeature([article_entity_1.Article, article_revision_entity_1.ArticleRevision]),
|
|
29
|
-
category_module_1.CategoryModule,
|
|
30
|
-
tag_module_1.TagModule,
|
|
31
|
-
user_module_1.UserModule,
|
|
32
|
-
auth_module_1.AuthModule,
|
|
33
|
-
api_key_module_1.ApiKeyModule,
|
|
34
|
-
webhook_module_1.WebhookModule,
|
|
35
|
-
],
|
|
23
|
+
imports: [typeorm_1.TypeOrmModule.forFeature([article_entity_1.Article]), category_module_1.CategoryModule, tag_module_1.TagModule, user_module_1.UserModule, auth_module_1.AuthModule],
|
|
36
24
|
exports: [article_service_1.ArticleService],
|
|
37
|
-
providers: [article_service_1.ArticleService
|
|
25
|
+
providers: [article_service_1.ArticleService],
|
|
38
26
|
controllers: [article_controller_1.ArticleController],
|
|
39
27
|
})
|
|
40
28
|
], ArticleModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"article.module.js","sourceRoot":"","sources":["../../../src/modules/article/article.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6CAAgD;AAEhD,
|
|
1
|
+
{"version":3,"file":"article.module.js","sourceRoot":"","sources":["../../../src/modules/article/article.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6CAAgD;AAEhD,qDAAiD;AACjD,iEAA6D;AAC7D,kDAA8C;AAC9C,qDAAiD;AACjD,6DAAyD;AACzD,qDAA2C;AAC3C,uDAAmD;AAQnD,IAAa,aAAa,GAA1B,MAAa,aAAa;CAAG,CAAA;AAAhB,aAAa;IANzB,eAAM,CAAC;QACN,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,wBAAO,CAAC,CAAC,EAAE,gCAAc,EAAE,sBAAS,EAAE,wBAAU,EAAE,wBAAU,CAAC;QACjG,OAAO,EAAE,CAAC,gCAAc,CAAC;QACzB,SAAS,EAAE,CAAC,gCAAc,CAAC;QAC3B,WAAW,EAAE,CAAC,sCAAiB,CAAC;KACjC,CAAC;GACW,aAAa,CAAG;AAAhB,sCAAa"}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import { Repository } from 'typeorm';
|
|
2
2
|
import { CategoryService } from '../category/category.service';
|
|
3
3
|
import { TagService } from '../tag/tag.service';
|
|
4
|
-
import { WebhookService } from '../webhook/webhook.service';
|
|
5
|
-
import { ArticleRevision } from './article-revision.entity';
|
|
6
4
|
import { Article } from './article.entity';
|
|
7
5
|
export declare class ArticleService {
|
|
8
6
|
private readonly articleRepository;
|
|
9
|
-
private readonly revisionRepository;
|
|
10
7
|
private readonly tagService;
|
|
11
8
|
private readonly categoryService;
|
|
12
|
-
|
|
13
|
-
constructor(articleRepository: Repository<Article>, revisionRepository: Repository<ArticleRevision>, tagService: TagService, categoryService: CategoryService, webhookService: WebhookService);
|
|
14
|
-
private saveRevision;
|
|
15
|
-
private notifyPublished;
|
|
9
|
+
constructor(articleRepository: Repository<Article>, tagService: TagService, categoryService: CategoryService);
|
|
16
10
|
create(article: Partial<Article>): Promise<Article>;
|
|
17
11
|
findAll(queryParams: any): Promise<[Article[], number]>;
|
|
18
12
|
findArticlesByCategory(category: any, queryParams: any): Promise<(number | Article[])[]>;
|
|
@@ -28,8 +22,6 @@ export declare class ArticleService {
|
|
|
28
22
|
}>;
|
|
29
23
|
findById(id: any, status?: any, isAdmin?: boolean): Promise<Article>;
|
|
30
24
|
updateById(id: any, article: Partial<Article>): Promise<Article>;
|
|
31
|
-
listRevisions(articleId: string): Promise<ArticleRevision[]>;
|
|
32
|
-
restoreRevision(articleId: string, revisionId: string): Promise<Article>;
|
|
33
25
|
updateViewsById(id: any): Promise<Article>;
|
|
34
26
|
updateLikesById(id: any, type: any): Promise<Article>;
|
|
35
27
|
deleteById(id: any): Promise<Article>;
|
|
@@ -24,49 +24,28 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ArticleService = void 0;
|
|
27
|
-
const api_messages_1 = require("../../common/api-messages");
|
|
28
27
|
const common_1 = require("@nestjs/common");
|
|
29
28
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
30
29
|
const typeorm_2 = require("typeorm");
|
|
31
30
|
const date_util_1 = require("../../utils/date.util");
|
|
32
31
|
const category_service_1 = require("../category/category.service");
|
|
33
32
|
const tag_service_1 = require("../tag/tag.service");
|
|
34
|
-
const webhook_service_1 = require("../webhook/webhook.service");
|
|
35
|
-
const article_revision_entity_1 = require("./article-revision.entity");
|
|
36
33
|
const article_entity_1 = require("./article.entity");
|
|
37
34
|
const article_util_1 = require("./article.util");
|
|
38
35
|
const Segment = require('segment');
|
|
39
36
|
const segment = new Segment();
|
|
40
37
|
segment.useDefault();
|
|
41
38
|
let ArticleService = class ArticleService {
|
|
42
|
-
constructor(articleRepository,
|
|
39
|
+
constructor(articleRepository, tagService, categoryService) {
|
|
43
40
|
this.articleRepository = articleRepository;
|
|
44
|
-
this.revisionRepository = revisionRepository;
|
|
45
41
|
this.tagService = tagService;
|
|
46
42
|
this.categoryService = categoryService;
|
|
47
|
-
this.webhookService = webhookService;
|
|
48
|
-
}
|
|
49
|
-
async saveRevision(article) {
|
|
50
|
-
const revision = this.revisionRepository.create({
|
|
51
|
-
articleId: article.id,
|
|
52
|
-
article,
|
|
53
|
-
title: article.title,
|
|
54
|
-
content: article.content,
|
|
55
|
-
html: article.html,
|
|
56
|
-
status: article.status,
|
|
57
|
-
});
|
|
58
|
-
await this.revisionRepository.save(revision);
|
|
59
|
-
}
|
|
60
|
-
async notifyPublished(article, extra = {}) {
|
|
61
|
-
if (article.status !== 'publish')
|
|
62
|
-
return;
|
|
63
|
-
await this.webhookService.dispatch('article.published', Object.assign({ id: article.id, title: article.title, status: article.status, publishAt: article.publishAt }, extra));
|
|
64
43
|
}
|
|
65
44
|
async create(article) {
|
|
66
45
|
const { title } = article;
|
|
67
46
|
const exist = await this.articleRepository.findOne({ where: { title } });
|
|
68
47
|
if (exist) {
|
|
69
|
-
throw new common_1.HttpException(
|
|
48
|
+
throw new common_1.HttpException('文章标题已存在', common_1.HttpStatus.BAD_REQUEST);
|
|
70
49
|
}
|
|
71
50
|
let { tags, category, status } = article;
|
|
72
51
|
if (status === 'publish') {
|
|
@@ -78,7 +57,6 @@ let ArticleService = class ArticleService {
|
|
|
78
57
|
const existCategory = await this.categoryService.findById(category);
|
|
79
58
|
const newArticle = await this.articleRepository.create(Object.assign(Object.assign({}, article), { category: existCategory, tags, needPassword: !!article.password }));
|
|
80
59
|
await this.articleRepository.save(newArticle);
|
|
81
|
-
await this.notifyPublished(newArticle);
|
|
82
60
|
return newArticle;
|
|
83
61
|
}
|
|
84
62
|
async findAll(queryParams) {
|
|
@@ -220,47 +198,18 @@ let ArticleService = class ArticleService {
|
|
|
220
198
|
return data;
|
|
221
199
|
}
|
|
222
200
|
async updateById(id, article) {
|
|
223
|
-
var _a;
|
|
224
201
|
const oldArticle = await this.articleRepository.findOne(id);
|
|
225
|
-
await this.saveRevision(oldArticle);
|
|
226
202
|
let { tags, category, status } = article;
|
|
227
203
|
if (tags) {
|
|
228
204
|
tags = await this.tagService.findByIds(('' + tags).split(','));
|
|
229
205
|
}
|
|
230
206
|
const existCategory = await this.categoryService.findById(category);
|
|
231
|
-
const
|
|
232
|
-
const newArticle = Object.assign(Object.assign({}, article), { views: oldArticle.views, category: existCategory, needPassword: !!article.password, publishAt: becomingPublish ? date_util_1.dateFormat() : oldArticle.publishAt, scheduledPublishAt: status === 'publish' ? null : (_a = article.scheduledPublishAt) !== null && _a !== void 0 ? _a : oldArticle.scheduledPublishAt });
|
|
207
|
+
const newArticle = Object.assign(Object.assign({}, article), { views: oldArticle.views, category: existCategory, needPassword: !!article.password, publishAt: oldArticle.status === 'draft' && status === 'publish' ? date_util_1.dateFormat() : oldArticle.publishAt });
|
|
233
208
|
if (tags) {
|
|
234
209
|
Object.assign(newArticle, { tags });
|
|
235
210
|
}
|
|
236
211
|
const updatedArticle = await this.articleRepository.merge(oldArticle, newArticle);
|
|
237
|
-
|
|
238
|
-
if (becomingPublish) {
|
|
239
|
-
await this.notifyPublished(saved);
|
|
240
|
-
}
|
|
241
|
-
return saved;
|
|
242
|
-
}
|
|
243
|
-
async listRevisions(articleId) {
|
|
244
|
-
return this.revisionRepository.find({
|
|
245
|
-
where: { articleId },
|
|
246
|
-
order: { createAt: 'DESC' },
|
|
247
|
-
take: 50,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
async restoreRevision(articleId, revisionId) {
|
|
251
|
-
const revision = await this.revisionRepository.findOne(revisionId);
|
|
252
|
-
if (!revision || revision.articleId !== articleId) {
|
|
253
|
-
throw new common_1.HttpException(api_messages_1.ApiMsg.REVISION_NOT_FOUND, common_1.HttpStatus.NOT_FOUND);
|
|
254
|
-
}
|
|
255
|
-
const article = await this.articleRepository.findOne(articleId);
|
|
256
|
-
await this.saveRevision(article);
|
|
257
|
-
const restored = await this.articleRepository.merge(article, {
|
|
258
|
-
title: revision.title,
|
|
259
|
-
content: revision.content,
|
|
260
|
-
html: revision.html,
|
|
261
|
-
status: revision.status,
|
|
262
|
-
});
|
|
263
|
-
return this.articleRepository.save(restored);
|
|
212
|
+
return this.articleRepository.save(updatedArticle);
|
|
264
213
|
}
|
|
265
214
|
async updateViewsById(id) {
|
|
266
215
|
const oldArticle = await this.articleRepository.findOne(id);
|
|
@@ -346,12 +295,9 @@ let ArticleService = class ArticleService {
|
|
|
346
295
|
ArticleService = __decorate([
|
|
347
296
|
common_1.Injectable(),
|
|
348
297
|
__param(0, typeorm_1.InjectRepository(article_entity_1.Article)),
|
|
349
|
-
__param(1, typeorm_1.InjectRepository(article_revision_entity_1.ArticleRevision)),
|
|
350
298
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
351
|
-
typeorm_2.Repository,
|
|
352
299
|
tag_service_1.TagService,
|
|
353
|
-
category_service_1.CategoryService
|
|
354
|
-
webhook_service_1.WebhookService])
|
|
300
|
+
category_service_1.CategoryService])
|
|
355
301
|
], ArticleService);
|
|
356
302
|
exports.ArticleService = ArticleService;
|
|
357
303
|
//# sourceMappingURL=article.service.js.map
|