@aphexcms/cms-core 3.0.0 → 5.0.0
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/dist/api/schemas/user.d.ts +10 -0
- package/dist/api/schemas/user.d.ts.map +1 -1
- package/dist/api/schemas/user.js +10 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -2
- package/dist/hooks.d.ts +3 -4
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +20 -99
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -4
- package/dist/lib/api/schemas/user.d.ts +10 -0
- package/dist/lib/api/schemas/user.d.ts.map +1 -1
- package/dist/lib/api/schemas/user.js +10 -0
- package/dist/lib/api/schemas/user.js.map +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +1 -2
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/hooks.d.ts +3 -4
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +20 -99
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/index.d.ts +9 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +43 -4
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/server/api/index.d.ts +55 -0
- package/dist/lib/server/api/index.d.ts.map +1 -0
- package/dist/lib/server/api/index.js +107 -0
- package/dist/lib/server/api/index.js.map +1 -0
- package/dist/lib/server/api/routes/assets-bulk.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -0
- package/dist/{routes → lib/server/api/routes}/assets-bulk.js +23 -23
- package/dist/lib/server/api/routes/assets-bulk.js.map +1 -0
- package/dist/lib/server/api/routes/assets-by-id.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-by-id.js +108 -0
- package/dist/lib/server/api/routes/assets-by-id.js.map +1 -0
- package/dist/lib/server/api/routes/assets-references.d.ts +15 -0
- package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-references.js +78 -0
- package/dist/lib/server/api/routes/assets-references.js.map +1 -0
- package/dist/lib/server/api/routes/assets.d.ts +4 -0
- package/dist/lib/server/api/routes/assets.d.ts.map +1 -0
- package/dist/{routes → lib/server/api/routes}/assets.js +76 -87
- package/dist/lib/server/api/routes/assets.js.map +1 -0
- package/dist/lib/server/api/routes/document-versions.d.ts +4 -0
- package/dist/lib/server/api/routes/document-versions.d.ts.map +1 -0
- package/dist/lib/server/api/routes/document-versions.js +113 -0
- package/dist/lib/server/api/routes/document-versions.js.map +1 -0
- package/dist/lib/server/api/routes/documents-by-id.d.ts +4 -0
- package/dist/lib/server/api/routes/documents-by-id.d.ts.map +1 -0
- package/dist/lib/server/api/routes/documents-by-id.js +148 -0
- package/dist/lib/server/api/routes/documents-by-id.js.map +1 -0
- package/dist/lib/server/api/routes/documents-publish.d.ts +4 -0
- package/dist/lib/server/api/routes/documents-publish.d.ts.map +1 -0
- package/dist/{routes → lib/server/api/routes}/documents-publish.js +42 -58
- package/dist/lib/server/api/routes/documents-publish.js.map +1 -0
- package/dist/lib/server/api/routes/documents-query.d.ts +8 -0
- package/dist/lib/server/api/routes/documents-query.d.ts.map +1 -0
- package/dist/lib/server/api/routes/documents-query.js +75 -0
- package/dist/lib/server/api/routes/documents-query.js.map +1 -0
- package/dist/lib/server/api/routes/documents.d.ts +4 -0
- package/dist/lib/server/api/routes/documents.d.ts.map +1 -0
- package/dist/{routes → lib/server/api/routes}/documents.js +55 -76
- package/dist/lib/server/api/routes/documents.js.map +1 -0
- package/dist/lib/server/api/routes/organizations-by-id.d.ts +4 -0
- package/dist/lib/server/api/routes/organizations-by-id.d.ts.map +1 -0
- package/dist/{routes → lib/server/api/routes}/organizations-by-id.js +62 -91
- package/dist/lib/server/api/routes/organizations-by-id.js.map +1 -0
- package/dist/lib/server/api/routes/organizations-invitations.d.ts +10 -0
- package/dist/lib/server/api/routes/organizations-invitations.d.ts.map +1 -0
- package/dist/{routes → lib/server/api/routes}/organizations-invitations.js +67 -78
- package/dist/lib/server/api/routes/organizations-invitations.js.map +1 -0
- package/dist/lib/server/api/routes/organizations-members.d.ts +4 -0
- package/dist/lib/server/api/routes/organizations-members.d.ts.map +1 -0
- package/dist/{routes → lib/server/api/routes}/organizations-members.js +74 -106
- package/dist/lib/server/api/routes/organizations-members.js.map +1 -0
- package/dist/lib/server/api/routes/organizations-switch.d.ts +4 -0
- package/dist/lib/server/api/routes/organizations-switch.d.ts.map +1 -0
- package/dist/lib/server/api/routes/organizations-switch.js +54 -0
- package/dist/lib/server/api/routes/organizations-switch.js.map +1 -0
- package/dist/lib/server/api/routes/organizations.d.ts +4 -0
- package/dist/lib/server/api/routes/organizations.d.ts.map +1 -0
- package/dist/lib/server/api/routes/organizations.js +99 -0
- package/dist/lib/server/api/routes/organizations.js.map +1 -0
- package/dist/lib/server/api/routes/roles.d.ts +12 -0
- package/dist/lib/server/api/routes/roles.d.ts.map +1 -0
- package/dist/lib/server/api/routes/roles.js +219 -0
- package/dist/lib/server/api/routes/roles.js.map +1 -0
- package/dist/lib/server/api/routes/schemas.d.ts +4 -0
- package/dist/lib/server/api/routes/schemas.d.ts.map +1 -0
- package/dist/lib/server/api/routes/schemas.js +27 -0
- package/dist/lib/server/api/routes/schemas.js.map +1 -0
- package/dist/lib/server/api/routes/user-preferences.d.ts +4 -0
- package/dist/lib/server/api/routes/user-preferences.d.ts.map +1 -0
- package/dist/lib/server/api/routes/user-preferences.js +63 -0
- package/dist/lib/server/api/routes/user-preferences.js.map +1 -0
- package/dist/lib/server/api/routes/user.d.ts +12 -0
- package/dist/lib/server/api/routes/user.d.ts.map +1 -0
- package/dist/lib/server/api/routes/user.js +114 -0
- package/dist/lib/server/api/routes/user.js.map +1 -0
- package/dist/lib/server/index.d.ts +2 -1
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +7 -3
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/types/config.d.ts +28 -29
- package/dist/lib/types/config.d.ts.map +1 -1
- package/dist/server/api/index.d.ts +55 -0
- package/dist/server/api/index.d.ts.map +1 -0
- package/dist/server/api/index.js +106 -0
- package/dist/server/api/routes/assets-bulk.d.ts +4 -0
- package/dist/server/api/routes/assets-bulk.d.ts.map +1 -0
- package/dist/{lib → server/api}/routes/assets-bulk.js +22 -24
- package/dist/server/api/routes/assets-by-id.d.ts +4 -0
- package/dist/server/api/routes/assets-by-id.d.ts.map +1 -0
- package/dist/server/api/routes/assets-by-id.js +107 -0
- package/dist/server/api/routes/assets-references.d.ts +15 -0
- package/dist/server/api/routes/assets-references.d.ts.map +1 -0
- package/dist/server/api/routes/assets-references.js +77 -0
- package/dist/server/api/routes/assets.d.ts +4 -0
- package/dist/server/api/routes/assets.d.ts.map +1 -0
- package/dist/{lib → server/api}/routes/assets.js +75 -88
- package/dist/server/api/routes/document-versions.d.ts +4 -0
- package/dist/server/api/routes/document-versions.d.ts.map +1 -0
- package/dist/server/api/routes/document-versions.js +112 -0
- package/dist/server/api/routes/documents-by-id.d.ts +4 -0
- package/dist/server/api/routes/documents-by-id.d.ts.map +1 -0
- package/dist/server/api/routes/documents-by-id.js +147 -0
- package/dist/server/api/routes/documents-publish.d.ts +4 -0
- package/dist/server/api/routes/documents-publish.d.ts.map +1 -0
- package/dist/{lib → server/api}/routes/documents-publish.js +41 -59
- package/dist/server/api/routes/documents-query.d.ts +8 -0
- package/dist/server/api/routes/documents-query.d.ts.map +1 -0
- package/dist/server/api/routes/documents-query.js +74 -0
- package/dist/server/api/routes/documents.d.ts +4 -0
- package/dist/server/api/routes/documents.d.ts.map +1 -0
- package/dist/{lib → server/api}/routes/documents.js +54 -77
- package/dist/server/api/routes/organizations-by-id.d.ts +4 -0
- package/dist/server/api/routes/organizations-by-id.d.ts.map +1 -0
- package/dist/{lib → server/api}/routes/organizations-by-id.js +61 -92
- package/dist/server/api/routes/organizations-invitations.d.ts +10 -0
- package/dist/server/api/routes/organizations-invitations.d.ts.map +1 -0
- package/dist/{lib → server/api}/routes/organizations-invitations.js +66 -79
- package/dist/server/api/routes/organizations-members.d.ts +4 -0
- package/dist/server/api/routes/organizations-members.d.ts.map +1 -0
- package/dist/{lib → server/api}/routes/organizations-members.js +73 -107
- package/dist/server/api/routes/organizations-switch.d.ts +4 -0
- package/dist/server/api/routes/organizations-switch.d.ts.map +1 -0
- package/dist/server/api/routes/organizations-switch.js +53 -0
- package/dist/server/api/routes/organizations.d.ts +4 -0
- package/dist/server/api/routes/organizations.d.ts.map +1 -0
- package/dist/server/api/routes/organizations.js +98 -0
- package/dist/server/api/routes/roles.d.ts +12 -0
- package/dist/server/api/routes/roles.d.ts.map +1 -0
- package/dist/server/api/routes/roles.js +218 -0
- package/dist/server/api/routes/schemas.d.ts +4 -0
- package/dist/server/api/routes/schemas.d.ts.map +1 -0
- package/dist/server/api/routes/schemas.js +26 -0
- package/dist/server/api/routes/user-preferences.d.ts +4 -0
- package/dist/server/api/routes/user-preferences.d.ts.map +1 -0
- package/dist/server/api/routes/user-preferences.js +62 -0
- package/dist/server/api/routes/user.d.ts +12 -0
- package/dist/server/api/routes/user.d.ts.map +1 -0
- package/dist/server/api/routes/user.js +113 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +7 -3
- package/dist/types/config.d.ts +28 -29
- package/dist/types/config.d.ts.map +1 -1
- package/package.json +4 -2
- package/dist/lib/routes/assets-bulk.d.ts +0 -3
- package/dist/lib/routes/assets-bulk.d.ts.map +0 -1
- package/dist/lib/routes/assets-bulk.js.map +0 -1
- package/dist/lib/routes/assets-by-id.d.ts +0 -5
- package/dist/lib/routes/assets-by-id.d.ts.map +0 -1
- package/dist/lib/routes/assets-by-id.js +0 -116
- package/dist/lib/routes/assets-by-id.js.map +0 -1
- package/dist/lib/routes/assets-references-counts.d.ts +0 -7
- package/dist/lib/routes/assets-references-counts.d.ts.map +0 -1
- package/dist/lib/routes/assets-references-counts.js +0 -42
- package/dist/lib/routes/assets-references-counts.js.map +0 -1
- package/dist/lib/routes/assets-references.d.ts +0 -7
- package/dist/lib/routes/assets-references.d.ts.map +0 -1
- package/dist/lib/routes/assets-references.js +0 -35
- package/dist/lib/routes/assets-references.js.map +0 -1
- package/dist/lib/routes/assets.d.ts +0 -4
- package/dist/lib/routes/assets.d.ts.map +0 -1
- package/dist/lib/routes/assets.js.map +0 -1
- package/dist/lib/routes/document-versions.d.ts +0 -5
- package/dist/lib/routes/document-versions.d.ts.map +0 -1
- package/dist/lib/routes/document-versions.js +0 -114
- package/dist/lib/routes/document-versions.js.map +0 -1
- package/dist/lib/routes/documents-by-id.d.ts +0 -5
- package/dist/lib/routes/documents-by-id.d.ts.map +0 -1
- package/dist/lib/routes/documents-by-id.js +0 -188
- package/dist/lib/routes/documents-by-id.js.map +0 -1
- package/dist/lib/routes/documents-publish.d.ts +0 -4
- package/dist/lib/routes/documents-publish.d.ts.map +0 -1
- package/dist/lib/routes/documents-publish.js.map +0 -1
- package/dist/lib/routes/documents-query.d.ts +0 -26
- package/dist/lib/routes/documents-query.d.ts.map +0 -1
- package/dist/lib/routes/documents-query.js +0 -104
- package/dist/lib/routes/documents-query.js.map +0 -1
- package/dist/lib/routes/documents.d.ts +0 -4
- package/dist/lib/routes/documents.d.ts.map +0 -1
- package/dist/lib/routes/documents.js.map +0 -1
- package/dist/lib/routes/index.d.ts +0 -9
- package/dist/lib/routes/index.d.ts.map +0 -1
- package/dist/lib/routes/index.js +0 -15
- package/dist/lib/routes/index.js.map +0 -1
- package/dist/lib/routes/organizations-by-id.d.ts +0 -5
- package/dist/lib/routes/organizations-by-id.d.ts.map +0 -1
- package/dist/lib/routes/organizations-by-id.js.map +0 -1
- package/dist/lib/routes/organizations-invitations.d.ts +0 -4
- package/dist/lib/routes/organizations-invitations.d.ts.map +0 -1
- package/dist/lib/routes/organizations-invitations.js.map +0 -1
- package/dist/lib/routes/organizations-members.d.ts +0 -5
- package/dist/lib/routes/organizations-members.d.ts.map +0 -1
- package/dist/lib/routes/organizations-members.js.map +0 -1
- package/dist/lib/routes/organizations-switch.d.ts +0 -3
- package/dist/lib/routes/organizations-switch.d.ts.map +0 -1
- package/dist/lib/routes/organizations-switch.js +0 -59
- package/dist/lib/routes/organizations-switch.js.map +0 -1
- package/dist/lib/routes/organizations.d.ts +0 -4
- package/dist/lib/routes/organizations.d.ts.map +0 -1
- package/dist/lib/routes/organizations.js +0 -117
- package/dist/lib/routes/organizations.js.map +0 -1
- package/dist/lib/routes/roles-by-name.d.ts +0 -4
- package/dist/lib/routes/roles-by-name.d.ts.map +0 -1
- package/dist/lib/routes/roles-by-name.js +0 -112
- package/dist/lib/routes/roles-by-name.js.map +0 -1
- package/dist/lib/routes/roles.d.ts +0 -4
- package/dist/lib/routes/roles.d.ts.map +0 -1
- package/dist/lib/routes/roles.js +0 -91
- package/dist/lib/routes/roles.js.map +0 -1
- package/dist/lib/routes/schemas-by-type.d.ts +0 -3
- package/dist/lib/routes/schemas-by-type.d.ts.map +0 -1
- package/dist/lib/routes/schemas-by-type.js +0 -27
- package/dist/lib/routes/schemas-by-type.js.map +0 -1
- package/dist/lib/routes/schemas.d.ts +0 -3
- package/dist/lib/routes/schemas.d.ts.map +0 -1
- package/dist/lib/routes/schemas.js +0 -12
- package/dist/lib/routes/schemas.js.map +0 -1
- package/dist/lib/routes/user-preferences.d.ts +0 -4
- package/dist/lib/routes/user-preferences.d.ts.map +0 -1
- package/dist/lib/routes/user-preferences.js +0 -73
- package/dist/lib/routes/user-preferences.js.map +0 -1
- package/dist/lib/routes-exports.d.ts +0 -20
- package/dist/lib/routes-exports.d.ts.map +0 -1
- package/dist/lib/routes-exports.js +0 -27
- package/dist/lib/routes-exports.js.map +0 -1
- package/dist/routes/assets-bulk.d.ts +0 -3
- package/dist/routes/assets-bulk.d.ts.map +0 -1
- package/dist/routes/assets-by-id.d.ts +0 -5
- package/dist/routes/assets-by-id.d.ts.map +0 -1
- package/dist/routes/assets-by-id.js +0 -115
- package/dist/routes/assets-references-counts.d.ts +0 -7
- package/dist/routes/assets-references-counts.d.ts.map +0 -1
- package/dist/routes/assets-references-counts.js +0 -41
- package/dist/routes/assets-references.d.ts +0 -7
- package/dist/routes/assets-references.d.ts.map +0 -1
- package/dist/routes/assets-references.js +0 -34
- package/dist/routes/assets.d.ts +0 -4
- package/dist/routes/assets.d.ts.map +0 -1
- package/dist/routes/document-versions.d.ts +0 -5
- package/dist/routes/document-versions.d.ts.map +0 -1
- package/dist/routes/document-versions.js +0 -113
- package/dist/routes/documents-by-id.d.ts +0 -5
- package/dist/routes/documents-by-id.d.ts.map +0 -1
- package/dist/routes/documents-by-id.js +0 -187
- package/dist/routes/documents-publish.d.ts +0 -4
- package/dist/routes/documents-publish.d.ts.map +0 -1
- package/dist/routes/documents-query.d.ts +0 -26
- package/dist/routes/documents-query.d.ts.map +0 -1
- package/dist/routes/documents-query.js +0 -103
- package/dist/routes/documents.d.ts +0 -4
- package/dist/routes/documents.d.ts.map +0 -1
- package/dist/routes/index.d.ts +0 -9
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/index.js +0 -14
- package/dist/routes/organizations-by-id.d.ts +0 -5
- package/dist/routes/organizations-by-id.d.ts.map +0 -1
- package/dist/routes/organizations-invitations.d.ts +0 -4
- package/dist/routes/organizations-invitations.d.ts.map +0 -1
- package/dist/routes/organizations-members.d.ts +0 -5
- package/dist/routes/organizations-members.d.ts.map +0 -1
- package/dist/routes/organizations-switch.d.ts +0 -3
- package/dist/routes/organizations-switch.d.ts.map +0 -1
- package/dist/routes/organizations-switch.js +0 -58
- package/dist/routes/organizations.d.ts +0 -4
- package/dist/routes/organizations.d.ts.map +0 -1
- package/dist/routes/organizations.js +0 -116
- package/dist/routes/roles-by-name.d.ts +0 -4
- package/dist/routes/roles-by-name.d.ts.map +0 -1
- package/dist/routes/roles-by-name.js +0 -111
- package/dist/routes/roles.d.ts +0 -4
- package/dist/routes/roles.d.ts.map +0 -1
- package/dist/routes/roles.js +0 -90
- package/dist/routes/schemas-by-type.d.ts +0 -3
- package/dist/routes/schemas-by-type.d.ts.map +0 -1
- package/dist/routes/schemas-by-type.js +0 -26
- package/dist/routes/schemas.d.ts +0 -3
- package/dist/routes/schemas.d.ts.map +0 -1
- package/dist/routes/schemas.js +0 -11
- package/dist/routes/user-preferences.d.ts +0 -4
- package/dist/routes/user-preferences.d.ts.map +0 -1
- package/dist/routes/user-preferences.js +0 -72
- package/dist/routes-exports.d.ts +0 -20
- package/dist/routes-exports.d.ts.map +0 -1
- package/dist/routes-exports.js +0 -26
|
@@ -1,50 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { cmsLogger } from '
|
|
4
|
-
import { validateFile } from '
|
|
5
|
-
import { listAssetsQuery } from '
|
|
6
|
-
export const
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { zValidator } from '@hono/zod-validator';
|
|
3
|
+
import { cmsLogger } from '../../../utils/logger.js';
|
|
4
|
+
import { validateFile } from '../../../utils/mime-detect.js';
|
|
5
|
+
import { listAssetsQuery } from '../../../api/schemas/assets.js';
|
|
6
|
+
export const assetsRouter = new Hono()
|
|
7
|
+
.get('/', zValidator('query', listAssetsQuery, (result, c) => {
|
|
8
|
+
if (!result.success) {
|
|
9
|
+
return c.json({
|
|
10
|
+
success: false,
|
|
11
|
+
error: 'Invalid query parameters',
|
|
12
|
+
issues: result.error.issues
|
|
13
|
+
}, 400);
|
|
14
|
+
}
|
|
15
|
+
}), async (c) => {
|
|
16
|
+
try {
|
|
17
|
+
const { assetService } = c.var.aphexCMS;
|
|
18
|
+
const auth = c.var.auth;
|
|
19
|
+
if (!auth || auth.type === 'partial_session') {
|
|
20
|
+
return c.json({ success: false, error: 'Unauthorized' }, 401);
|
|
21
|
+
}
|
|
22
|
+
const q = c.req.valid('query');
|
|
23
|
+
const filters = {
|
|
24
|
+
assetType: q.assetType,
|
|
25
|
+
mimeType: q.mimeType,
|
|
26
|
+
search: q.search,
|
|
27
|
+
limit: q.limit ?? 20,
|
|
28
|
+
offset: q.offset ?? 0
|
|
29
|
+
};
|
|
30
|
+
const [fetchedAssets, totalAssets] = await Promise.all([
|
|
31
|
+
assetService.findAssets(auth.organizationId, filters),
|
|
32
|
+
assetService.findAssets(auth.organizationId, {
|
|
33
|
+
...filters,
|
|
34
|
+
limit: 999999,
|
|
35
|
+
offset: 0
|
|
36
|
+
})
|
|
37
|
+
]);
|
|
38
|
+
const total = totalAssets.length;
|
|
39
|
+
const pageSize = filters.limit || 20;
|
|
40
|
+
const currentPage = Math.floor(filters.offset / pageSize) + 1;
|
|
41
|
+
const totalPages = Math.ceil(total / pageSize);
|
|
42
|
+
return c.json({
|
|
43
|
+
success: true,
|
|
44
|
+
data: fetchedAssets,
|
|
45
|
+
pagination: {
|
|
46
|
+
total,
|
|
47
|
+
page: currentPage,
|
|
48
|
+
pageSize,
|
|
49
|
+
totalPages,
|
|
50
|
+
hasNextPage: currentPage < totalPages,
|
|
51
|
+
hasPrevPage: currentPage > 1
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
cmsLogger.error('Failed to fetch assets:', error);
|
|
57
|
+
return c.json({
|
|
58
|
+
success: false,
|
|
59
|
+
error: 'Failed to fetch assets',
|
|
60
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
61
|
+
}, 500);
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
.post('/', async (c) => {
|
|
7
65
|
try {
|
|
8
|
-
const { assetService } =
|
|
9
|
-
const auth =
|
|
66
|
+
const { assetService } = c.var.aphexCMS;
|
|
67
|
+
const auth = c.var.auth;
|
|
10
68
|
if (!auth || auth.type === 'partial_session') {
|
|
11
|
-
return json({ success: false, error: 'Unauthorized' },
|
|
69
|
+
return c.json({ success: false, error: 'Unauthorized' }, 401);
|
|
12
70
|
}
|
|
13
|
-
const formData = await
|
|
71
|
+
const formData = await c.req.formData();
|
|
14
72
|
const file = formData.get('file');
|
|
15
73
|
if (!file) {
|
|
16
|
-
return json({ success: false, error: 'No file provided' },
|
|
74
|
+
return c.json({ success: false, error: 'No file provided' }, 400);
|
|
17
75
|
}
|
|
18
|
-
// Convert file to buffer
|
|
19
76
|
const arrayBuffer = await file.arrayBuffer();
|
|
20
77
|
const buffer = Buffer.from(arrayBuffer);
|
|
21
|
-
// Get allowed MIME types and max size from form data (set by FileField component)
|
|
22
78
|
const allowedMimeTypesRaw = formData.get('allowedMimeTypes');
|
|
23
79
|
const maxSizeRaw = formData.get('maxSize');
|
|
24
80
|
const allowedMimeTypes = allowedMimeTypesRaw ? JSON.parse(allowedMimeTypesRaw) : undefined;
|
|
25
81
|
const maxSize = maxSizeRaw ? parseInt(maxSizeRaw, 10) : undefined;
|
|
26
|
-
// Validate file content (magic bytes, blocked types, allowed types)
|
|
27
82
|
const validation = validateFile(buffer, file.name, file.type, {
|
|
28
83
|
allowedMimeTypes,
|
|
29
84
|
maxSize
|
|
30
85
|
});
|
|
31
86
|
if (!validation.valid) {
|
|
32
|
-
return json({ success: false, error: validation.error },
|
|
87
|
+
return c.json({ success: false, error: validation.error }, 400);
|
|
33
88
|
}
|
|
34
|
-
// Get optional metadata from form data
|
|
35
89
|
const title = formData.get('title') || undefined;
|
|
36
90
|
const description = formData.get('description') || undefined;
|
|
37
91
|
const alt = formData.get('alt') || undefined;
|
|
38
92
|
const creditLine = formData.get('creditLine') || undefined;
|
|
39
|
-
// Get field metadata for privacy checking
|
|
40
93
|
const schemaType = formData.get('schemaType') || undefined;
|
|
41
94
|
const fieldPath = formData.get('fieldPath') || undefined;
|
|
42
|
-
// Get target organization (document's org takes precedence)
|
|
43
|
-
// This allows assets to belong to the document's org, not the uploader's org
|
|
44
95
|
const targetOrganizationId = formData.get('organizationId') || auth.organizationId;
|
|
45
|
-
// Create asset upload data
|
|
46
96
|
const uploadData = {
|
|
47
|
-
organizationId: targetOrganizationId,
|
|
97
|
+
organizationId: targetOrganizationId,
|
|
48
98
|
buffer,
|
|
49
99
|
originalFilename: file.name,
|
|
50
100
|
mimeType: file.type,
|
|
@@ -59,78 +109,15 @@ export const POST = async ({ request, locals }) => {
|
|
|
59
109
|
fieldPath
|
|
60
110
|
}
|
|
61
111
|
};
|
|
62
|
-
// Upload asset using the service
|
|
63
|
-
// The adapter will validate hierarchy access via withOrgContext
|
|
64
112
|
const asset = await assetService.uploadAsset(targetOrganizationId, uploadData);
|
|
65
|
-
return json({
|
|
66
|
-
success: true,
|
|
67
|
-
data: asset
|
|
68
|
-
});
|
|
113
|
+
return c.json({ success: true, data: asset });
|
|
69
114
|
}
|
|
70
115
|
catch (error) {
|
|
71
116
|
cmsLogger.error('Asset upload failed:', error);
|
|
72
|
-
return json({
|
|
117
|
+
return c.json({
|
|
73
118
|
success: false,
|
|
74
119
|
error: 'Asset upload failed',
|
|
75
120
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
export const GET = async ({ url, locals }) => {
|
|
80
|
-
try {
|
|
81
|
-
const { assetService } = locals.aphexCMS;
|
|
82
|
-
const auth = locals.auth;
|
|
83
|
-
if (!auth || auth.type === 'partial_session') {
|
|
84
|
-
return json({ success: false, error: 'Unauthorized' }, { status: 401 });
|
|
85
|
-
}
|
|
86
|
-
const parsedQuery = listAssetsQuery.safeParse(Object.fromEntries(url.searchParams.entries()));
|
|
87
|
-
if (!parsedQuery.success) {
|
|
88
|
-
return json({
|
|
89
|
-
success: false,
|
|
90
|
-
error: 'Invalid query parameters',
|
|
91
|
-
issues: parsedQuery.error.issues
|
|
92
|
-
}, { status: 400 });
|
|
93
|
-
}
|
|
94
|
-
const filters = {
|
|
95
|
-
assetType: parsedQuery.data.assetType,
|
|
96
|
-
mimeType: parsedQuery.data.mimeType,
|
|
97
|
-
search: parsedQuery.data.search,
|
|
98
|
-
limit: parsedQuery.data.limit ?? 20,
|
|
99
|
-
offset: parsedQuery.data.offset ?? 0
|
|
100
|
-
};
|
|
101
|
-
// Fetch assets and total count in parallel
|
|
102
|
-
const [fetchedAssets, totalAssets] = await Promise.all([
|
|
103
|
-
assetService.findAssets(auth.organizationId, filters),
|
|
104
|
-
assetService.findAssets(auth.organizationId, {
|
|
105
|
-
...filters,
|
|
106
|
-
limit: 999999,
|
|
107
|
-
offset: 0
|
|
108
|
-
})
|
|
109
|
-
]);
|
|
110
|
-
const total = totalAssets.length;
|
|
111
|
-
const pageSize = filters.limit || 20;
|
|
112
|
-
const currentPage = Math.floor(filters.offset / pageSize) + 1;
|
|
113
|
-
const totalPages = Math.ceil(total / pageSize);
|
|
114
|
-
return json({
|
|
115
|
-
success: true,
|
|
116
|
-
data: fetchedAssets,
|
|
117
|
-
pagination: {
|
|
118
|
-
total,
|
|
119
|
-
page: currentPage,
|
|
120
|
-
pageSize,
|
|
121
|
-
totalPages,
|
|
122
|
-
hasNextPage: currentPage < totalPages,
|
|
123
|
-
hasPrevPage: currentPage > 1
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
cmsLogger.error('Failed to fetch assets:', error);
|
|
129
|
-
return json({
|
|
130
|
-
success: false,
|
|
131
|
-
error: 'Failed to fetch assets',
|
|
132
|
-
message: error instanceof Error ? error.message : 'Unknown error'
|
|
133
|
-
}, { status: 500 });
|
|
121
|
+
}, 500);
|
|
134
122
|
}
|
|
135
|
-
};
|
|
136
|
-
//# sourceMappingURL=assets.js.map
|
|
123
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-versions.d.ts","sourceRoot":"","sources":["../../../../src/lib/server/api/routes/document-versions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAK5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,eAAO,MAAM,sBAAsB,EAAE,IAAI,CAAC,QAAQ,CAqJ/C,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { zValidator } from '@hono/zod-validator';
|
|
3
|
+
import { authToContext } from '../../../local-api/auth-helpers.js';
|
|
4
|
+
import { cmsLogger } from '../../../utils/logger.js';
|
|
5
|
+
import { listVersionsQuery } from '../../../api/schemas/documents.js';
|
|
6
|
+
export const documentVersionsRouter = new Hono()
|
|
7
|
+
.get('/:id/versions', zValidator('query', listVersionsQuery, (result, c) => {
|
|
8
|
+
if (!result.success) {
|
|
9
|
+
return c.json({
|
|
10
|
+
success: false,
|
|
11
|
+
error: 'Invalid query parameters',
|
|
12
|
+
issues: result.error.issues
|
|
13
|
+
}, 400);
|
|
14
|
+
}
|
|
15
|
+
}), async (c) => {
|
|
16
|
+
try {
|
|
17
|
+
const { localAPI, databaseAdapter } = c.var.aphexCMS;
|
|
18
|
+
const context = authToContext(c.var.auth);
|
|
19
|
+
const id = c.req.param('id');
|
|
20
|
+
if (!id) {
|
|
21
|
+
return c.json({ success: false, error: 'Document ID is required' }, 400);
|
|
22
|
+
}
|
|
23
|
+
const q = c.req.valid('query');
|
|
24
|
+
const limit = q.limit ?? 25;
|
|
25
|
+
const offset = q.offset ?? 0;
|
|
26
|
+
const result = await localAPI.versionService.listVersions(databaseAdapter, context.organizationId, id, { limit, offset });
|
|
27
|
+
const userIds = [...new Set(result.versions.map((v) => v.createdBy).filter(Boolean))];
|
|
28
|
+
const userMap = new Map();
|
|
29
|
+
if (userIds.length > 0 && c.var.aphexCMS.auth) {
|
|
30
|
+
await Promise.all(userIds.map(async (userId) => {
|
|
31
|
+
if (userId.startsWith('apikey:')) {
|
|
32
|
+
userMap.set(userId, 'API Key');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const user = await c.var.aphexCMS.auth.getUserById(userId);
|
|
37
|
+
if (user) {
|
|
38
|
+
userMap.set(userId, user.name || user.email);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// User not found — skip
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
const versionsWithUsers = result.versions.map((v) => ({
|
|
47
|
+
...v,
|
|
48
|
+
createdByName: v.createdBy ? userMap.get(v.createdBy) || null : null
|
|
49
|
+
}));
|
|
50
|
+
return c.json({
|
|
51
|
+
success: true,
|
|
52
|
+
data: versionsWithUsers,
|
|
53
|
+
total: result.total
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
cmsLogger.error('Failed to list document versions:', error);
|
|
58
|
+
return c.json({ success: false, error: 'Failed to list versions' }, 500);
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
.get('/:id/versions/:version', async (c) => {
|
|
62
|
+
try {
|
|
63
|
+
const { localAPI, databaseAdapter } = c.var.aphexCMS;
|
|
64
|
+
const context = authToContext(c.var.auth);
|
|
65
|
+
const id = c.req.param('id');
|
|
66
|
+
const version = c.req.param('version');
|
|
67
|
+
if (!id || !version) {
|
|
68
|
+
return c.json({ success: false, error: 'Document ID and version number are required' }, 400);
|
|
69
|
+
}
|
|
70
|
+
const versionNumber = parseInt(version);
|
|
71
|
+
if (isNaN(versionNumber)) {
|
|
72
|
+
return c.json({ success: false, error: 'Version must be a number' }, 400);
|
|
73
|
+
}
|
|
74
|
+
const result = await localAPI.versionService.getVersion(databaseAdapter, context.organizationId, id, versionNumber);
|
|
75
|
+
if (!result) {
|
|
76
|
+
return c.json({ success: false, error: 'Version not found' }, 404);
|
|
77
|
+
}
|
|
78
|
+
return c.json({ success: true, data: result });
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
cmsLogger.error('Failed to get document version:', error);
|
|
82
|
+
return c.json({ success: false, error: 'Failed to get version' }, 500);
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
.post('/:id/versions/:version/restore', async (c) => {
|
|
86
|
+
try {
|
|
87
|
+
const { localAPI, databaseAdapter } = c.var.aphexCMS;
|
|
88
|
+
const context = authToContext(c.var.auth);
|
|
89
|
+
const id = c.req.param('id');
|
|
90
|
+
const version = c.req.param('version');
|
|
91
|
+
if (!id || !version) {
|
|
92
|
+
return c.json({ success: false, error: 'Document ID and version number are required' }, 400);
|
|
93
|
+
}
|
|
94
|
+
const versionNumber = parseInt(version);
|
|
95
|
+
if (isNaN(versionNumber)) {
|
|
96
|
+
return c.json({ success: false, error: 'Version must be a number' }, 400);
|
|
97
|
+
}
|
|
98
|
+
const document = await localAPI.versionService.restoreVersion(databaseAdapter, context.organizationId, id, versionNumber, context.user?.id);
|
|
99
|
+
if (!document) {
|
|
100
|
+
return c.json({ success: false, error: 'Version not found or restore failed' }, 404);
|
|
101
|
+
}
|
|
102
|
+
return c.json({
|
|
103
|
+
success: true,
|
|
104
|
+
data: document,
|
|
105
|
+
message: `Restored to version ${versionNumber}`
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
cmsLogger.error('Failed to restore document version:', error);
|
|
110
|
+
return c.json({ success: false, error: 'Failed to restore version' }, 500);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents-by-id.d.ts","sourceRoot":"","sources":["../../../../src/lib/server/api/routes/documents-by-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAM5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,eAAO,MAAM,mBAAmB,EAAE,IAAI,CAAC,QAAQ,CA4L5C,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { zValidator } from '@hono/zod-validator';
|
|
3
|
+
import { authToContext } from '../../../local-api/auth-helpers.js';
|
|
4
|
+
import { PermissionError } from '../../../local-api/permissions.js';
|
|
5
|
+
import { cmsLogger } from '../../../utils/logger.js';
|
|
6
|
+
import { updateDocumentRequest } from '../../../api/schemas/documents.js';
|
|
7
|
+
export const documentsByIdRouter = new Hono()
|
|
8
|
+
.get('/:id', async (c) => {
|
|
9
|
+
try {
|
|
10
|
+
const { localAPI } = c.var.aphexCMS;
|
|
11
|
+
const context = authToContext(c.var.auth);
|
|
12
|
+
const id = c.req.param('id');
|
|
13
|
+
if (!id) {
|
|
14
|
+
return c.json({ success: false, error: 'Document ID is required' }, 400);
|
|
15
|
+
}
|
|
16
|
+
const depthParam = c.req.query('depth');
|
|
17
|
+
const depth = depthParam ? Math.max(0, Math.min(parseInt(depthParam), 5)) : 0;
|
|
18
|
+
const perspective = c.req.query('perspective') || 'draft';
|
|
19
|
+
const result = await localAPI.findDocumentById(context, id);
|
|
20
|
+
if (!result) {
|
|
21
|
+
return c.json({ success: false, error: 'Document not found' }, 404);
|
|
22
|
+
}
|
|
23
|
+
const collection = localAPI.collections[result.type];
|
|
24
|
+
if (!collection) {
|
|
25
|
+
return c.json({
|
|
26
|
+
success: false,
|
|
27
|
+
error: 'Invalid document type',
|
|
28
|
+
message: `Collection '${result.type}' not found`
|
|
29
|
+
}, 400);
|
|
30
|
+
}
|
|
31
|
+
const document = await collection.findByID(context, id, { depth, perspective });
|
|
32
|
+
if (!document) {
|
|
33
|
+
return c.json({ success: false, error: 'Document not found' }, 404);
|
|
34
|
+
}
|
|
35
|
+
return c.json({ success: true, data: document });
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
cmsLogger.error('Failed to fetch document:', error);
|
|
39
|
+
if (error instanceof PermissionError) {
|
|
40
|
+
return c.json({ success: false, error: 'Forbidden', message: error.message }, 403);
|
|
41
|
+
}
|
|
42
|
+
return c.json({
|
|
43
|
+
success: false,
|
|
44
|
+
error: 'Failed to fetch document',
|
|
45
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
46
|
+
}, 500);
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
.put('/:id', zValidator('json', updateDocumentRequest, (result, c) => {
|
|
50
|
+
if (!result.success) {
|
|
51
|
+
return c.json({
|
|
52
|
+
success: false,
|
|
53
|
+
error: 'Invalid request body',
|
|
54
|
+
issues: result.error.issues
|
|
55
|
+
}, 400);
|
|
56
|
+
}
|
|
57
|
+
}), async (c) => {
|
|
58
|
+
try {
|
|
59
|
+
const { localAPI } = c.var.aphexCMS;
|
|
60
|
+
const context = authToContext(c.var.auth);
|
|
61
|
+
const id = c.req.param('id');
|
|
62
|
+
if (!id) {
|
|
63
|
+
return c.json({ success: false, error: 'Document ID is required' }, 400);
|
|
64
|
+
}
|
|
65
|
+
const parsed = c.req.valid('json');
|
|
66
|
+
const documentData = parsed.draftData ?? parsed.data;
|
|
67
|
+
if (!documentData) {
|
|
68
|
+
return c.json({ success: false, error: 'Document data is required' }, 400);
|
|
69
|
+
}
|
|
70
|
+
const shouldPublish = parsed.publish ?? false;
|
|
71
|
+
const found = await localAPI.findDocumentById(context, id);
|
|
72
|
+
if (!found) {
|
|
73
|
+
return c.json({ success: false, error: 'Document not found' }, 404);
|
|
74
|
+
}
|
|
75
|
+
const collection = localAPI.collections[found.type];
|
|
76
|
+
if (!collection) {
|
|
77
|
+
return c.json({
|
|
78
|
+
success: false,
|
|
79
|
+
error: 'Invalid document type',
|
|
80
|
+
message: `Collection '${found.type}' not found`
|
|
81
|
+
}, 400);
|
|
82
|
+
}
|
|
83
|
+
const result = await collection.update(context, id, documentData, {
|
|
84
|
+
publish: shouldPublish
|
|
85
|
+
});
|
|
86
|
+
if (!result) {
|
|
87
|
+
return c.json({ success: false, error: 'Document not found' }, 404);
|
|
88
|
+
}
|
|
89
|
+
return c.json({
|
|
90
|
+
success: true,
|
|
91
|
+
data: result.document,
|
|
92
|
+
validation: result.validation
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
cmsLogger.error('Failed to update document:', error);
|
|
97
|
+
if (error instanceof PermissionError) {
|
|
98
|
+
return c.json({ success: false, error: 'Forbidden', message: error.message }, 403);
|
|
99
|
+
}
|
|
100
|
+
if (error instanceof Error && error.message.includes('validation errors')) {
|
|
101
|
+
return c.json({ success: false, error: 'Validation failed', message: error.message }, 400);
|
|
102
|
+
}
|
|
103
|
+
return c.json({
|
|
104
|
+
success: false,
|
|
105
|
+
error: 'Failed to update document',
|
|
106
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
107
|
+
}, 500);
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
.delete('/:id', async (c) => {
|
|
111
|
+
try {
|
|
112
|
+
const { localAPI } = c.var.aphexCMS;
|
|
113
|
+
const context = authToContext(c.var.auth);
|
|
114
|
+
const id = c.req.param('id');
|
|
115
|
+
if (!id) {
|
|
116
|
+
return c.json({ success: false, error: 'Document ID is required' }, 400);
|
|
117
|
+
}
|
|
118
|
+
const result = await localAPI.findDocumentById(context, id);
|
|
119
|
+
if (!result) {
|
|
120
|
+
return c.json({ success: false, error: 'Document not found' }, 404);
|
|
121
|
+
}
|
|
122
|
+
const collection = localAPI.collections[result.type];
|
|
123
|
+
if (!collection) {
|
|
124
|
+
return c.json({
|
|
125
|
+
success: false,
|
|
126
|
+
error: 'Invalid document type',
|
|
127
|
+
message: `Collection '${result.type}' not found`
|
|
128
|
+
}, 400);
|
|
129
|
+
}
|
|
130
|
+
const success = await collection.delete(context, id);
|
|
131
|
+
if (!success) {
|
|
132
|
+
return c.json({ success: false, error: 'Document not found' }, 404);
|
|
133
|
+
}
|
|
134
|
+
return c.json({ success: true, message: 'Document deleted successfully' });
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
cmsLogger.error('Failed to delete document:', error);
|
|
138
|
+
if (error instanceof PermissionError) {
|
|
139
|
+
return c.json({ success: false, error: 'Forbidden', message: error.message }, 403);
|
|
140
|
+
}
|
|
141
|
+
return c.json({
|
|
142
|
+
success: false,
|
|
143
|
+
error: 'Failed to delete document',
|
|
144
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
145
|
+
}, 500);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents-publish.d.ts","sourceRoot":"","sources":["../../../../src/lib/server/api/routes/documents-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,eAAO,MAAM,sBAAsB,EAAE,IAAI,CAAC,QAAQ,CAkK/C,CAAC"}
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const POST = async ({ params, locals }) => {
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { authToContext } from '../../../local-api/auth-helpers.js';
|
|
3
|
+
import { PermissionError } from '../../../local-api/permissions.js';
|
|
4
|
+
import { cmsLogger } from '../../../utils/logger.js';
|
|
5
|
+
export const documentsPublishRouter = new Hono()
|
|
6
|
+
.post('/:id/publish', async (c) => {
|
|
8
7
|
try {
|
|
9
|
-
const { localAPI } =
|
|
10
|
-
const context = authToContext(
|
|
11
|
-
const
|
|
8
|
+
const { localAPI } = c.var.aphexCMS;
|
|
9
|
+
const context = authToContext(c.var.auth);
|
|
10
|
+
const id = c.req.param('id');
|
|
12
11
|
if (!id) {
|
|
13
|
-
return json({
|
|
12
|
+
return c.json({
|
|
14
13
|
success: false,
|
|
15
14
|
error: 'Missing document ID',
|
|
16
15
|
message: 'Document ID is required'
|
|
17
|
-
},
|
|
16
|
+
}, 400);
|
|
18
17
|
}
|
|
19
|
-
// Fetch document to get its type (hierarchy-aware, no RLS transaction)
|
|
20
18
|
const found = await localAPI.findDocumentById(context, id);
|
|
21
19
|
if (!found) {
|
|
22
|
-
return json({
|
|
20
|
+
return c.json({
|
|
23
21
|
success: false,
|
|
24
22
|
error: 'Document not found',
|
|
25
23
|
message: 'Document may not exist'
|
|
26
|
-
},
|
|
24
|
+
}, 404);
|
|
27
25
|
}
|
|
28
|
-
// Get collection API (TypeScript-safe)
|
|
29
26
|
const collection = localAPI.collections[found.type];
|
|
30
27
|
if (!collection) {
|
|
31
|
-
return json({
|
|
28
|
+
return c.json({
|
|
32
29
|
success: false,
|
|
33
30
|
error: 'Invalid document type',
|
|
34
31
|
message: `Collection '${found.type}' not found`
|
|
35
|
-
},
|
|
32
|
+
}, 400);
|
|
36
33
|
}
|
|
37
|
-
// Publish via LocalAPI (permission checks and validation happen inside)
|
|
38
34
|
const publishedDocument = await collection.publish(context, id);
|
|
39
35
|
if (!publishedDocument) {
|
|
40
|
-
return json({
|
|
36
|
+
return c.json({
|
|
41
37
|
success: false,
|
|
42
38
|
error: 'Document not found or cannot be published',
|
|
43
39
|
message: 'Document may not have draft content to publish'
|
|
44
|
-
},
|
|
40
|
+
}, 404);
|
|
45
41
|
}
|
|
46
|
-
return json({
|
|
42
|
+
return c.json({
|
|
47
43
|
success: true,
|
|
48
44
|
data: publishedDocument,
|
|
49
45
|
message: 'Document published successfully'
|
|
@@ -52,68 +48,59 @@ export const POST = async ({ params, locals }) => {
|
|
|
52
48
|
catch (error) {
|
|
53
49
|
cmsLogger.error('Failed to publish document:', error);
|
|
54
50
|
if (error instanceof PermissionError) {
|
|
55
|
-
return json({
|
|
56
|
-
success: false,
|
|
57
|
-
error: 'Forbidden',
|
|
58
|
-
message: error.message
|
|
59
|
-
}, { status: 403 });
|
|
51
|
+
return c.json({ success: false, error: 'Forbidden', message: error.message }, 403);
|
|
60
52
|
}
|
|
61
|
-
// Validation errors from LocalAPI are regular errors with specific messages
|
|
62
53
|
if (error instanceof Error && error.message.includes('validation errors')) {
|
|
63
|
-
return json({
|
|
54
|
+
return c.json({
|
|
64
55
|
success: false,
|
|
65
56
|
error: 'Cannot publish: validation errors',
|
|
66
57
|
message: error.message
|
|
67
|
-
},
|
|
58
|
+
}, 400);
|
|
68
59
|
}
|
|
69
|
-
return json({
|
|
60
|
+
return c.json({
|
|
70
61
|
success: false,
|
|
71
62
|
error: 'Failed to publish document',
|
|
72
63
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
73
|
-
},
|
|
64
|
+
}, 500);
|
|
74
65
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const DELETE = async ({ params, locals }) => {
|
|
66
|
+
})
|
|
67
|
+
.delete('/:id/publish', async (c) => {
|
|
78
68
|
try {
|
|
79
|
-
const { localAPI } =
|
|
80
|
-
const context = authToContext(
|
|
81
|
-
const
|
|
69
|
+
const { localAPI } = c.var.aphexCMS;
|
|
70
|
+
const context = authToContext(c.var.auth);
|
|
71
|
+
const id = c.req.param('id');
|
|
82
72
|
if (!id) {
|
|
83
|
-
return json({
|
|
73
|
+
return c.json({
|
|
84
74
|
success: false,
|
|
85
75
|
error: 'Missing document ID',
|
|
86
76
|
message: 'Document ID is required'
|
|
87
|
-
},
|
|
77
|
+
}, 400);
|
|
88
78
|
}
|
|
89
|
-
// Fetch document to get its type (hierarchy-aware, no RLS transaction)
|
|
90
79
|
const found = await localAPI.findDocumentById(context, id);
|
|
91
80
|
if (!found) {
|
|
92
|
-
return json({
|
|
81
|
+
return c.json({
|
|
93
82
|
success: false,
|
|
94
83
|
error: 'Document not found',
|
|
95
84
|
message: `No document found with ID: ${id}`
|
|
96
|
-
},
|
|
85
|
+
}, 404);
|
|
97
86
|
}
|
|
98
|
-
// Get collection API (TypeScript-safe)
|
|
99
87
|
const collection = localAPI.collections[found.type];
|
|
100
88
|
if (!collection) {
|
|
101
|
-
return json({
|
|
89
|
+
return c.json({
|
|
102
90
|
success: false,
|
|
103
91
|
error: 'Invalid document type',
|
|
104
92
|
message: `Collection '${found.type}' not found`
|
|
105
|
-
},
|
|
93
|
+
}, 400);
|
|
106
94
|
}
|
|
107
|
-
// Unpublish via LocalAPI (permission checks happen inside)
|
|
108
95
|
const unpublishedDocument = await collection.unpublish(context, id);
|
|
109
96
|
if (!unpublishedDocument) {
|
|
110
|
-
return json({
|
|
97
|
+
return c.json({
|
|
111
98
|
success: false,
|
|
112
99
|
error: 'Document not found',
|
|
113
100
|
message: `No document found with ID: ${id}`
|
|
114
|
-
},
|
|
101
|
+
}, 404);
|
|
115
102
|
}
|
|
116
|
-
return json({
|
|
103
|
+
return c.json({
|
|
117
104
|
success: true,
|
|
118
105
|
data: unpublishedDocument,
|
|
119
106
|
message: 'Document unpublished successfully'
|
|
@@ -122,17 +109,12 @@ export const DELETE = async ({ params, locals }) => {
|
|
|
122
109
|
catch (error) {
|
|
123
110
|
cmsLogger.error('Failed to unpublish document:', error);
|
|
124
111
|
if (error instanceof PermissionError) {
|
|
125
|
-
return json({
|
|
126
|
-
success: false,
|
|
127
|
-
error: 'Forbidden',
|
|
128
|
-
message: error.message
|
|
129
|
-
}, { status: 403 });
|
|
112
|
+
return c.json({ success: false, error: 'Forbidden', message: error.message }, 403);
|
|
130
113
|
}
|
|
131
|
-
return json({
|
|
114
|
+
return c.json({
|
|
132
115
|
success: false,
|
|
133
116
|
error: 'Failed to unpublish document',
|
|
134
117
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
135
|
-
},
|
|
118
|
+
}, 500);
|
|
136
119
|
}
|
|
137
|
-
};
|
|
138
|
-
//# sourceMappingURL=documents-publish.js.map
|
|
120
|
+
});
|