digitaltwin-core 0.9.2 → 0.10.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/dist/auth/user_service.d.ts.map +1 -1
- package/dist/auth/user_service.js +0 -5
- package/dist/auth/user_service.js.map +1 -1
- package/dist/components/assets_manager.d.ts +11 -1
- package/dist/components/assets_manager.d.ts.map +1 -1
- package/dist/components/assets_manager.js +355 -9
- package/dist/components/assets_manager.js.map +1 -1
- package/dist/components/collector.d.ts +11 -1
- package/dist/components/collector.d.ts.map +1 -1
- package/dist/components/collector.js +43 -0
- package/dist/components/collector.js.map +1 -1
- package/dist/components/custom_table_manager.d.ts +19 -1
- package/dist/components/custom_table_manager.d.ts.map +1 -1
- package/dist/components/custom_table_manager.js +225 -0
- package/dist/components/custom_table_manager.js.map +1 -1
- package/dist/components/handler.d.ts +11 -1
- package/dist/components/handler.d.ts.map +1 -1
- package/dist/components/handler.js +44 -0
- package/dist/components/handler.js.map +1 -1
- package/dist/components/harvester.d.ts +11 -1
- package/dist/components/harvester.d.ts.map +1 -1
- package/dist/components/harvester.js +43 -0
- package/dist/components/harvester.js.map +1 -1
- package/dist/components/tileset_manager.d.ts +10 -0
- package/dist/components/tileset_manager.d.ts.map +1 -1
- package/dist/components/tileset_manager.js +65 -0
- package/dist/components/tileset_manager.js.map +1 -1
- package/dist/components/types.d.ts +2 -0
- package/dist/components/types.d.ts.map +1 -1
- package/dist/engine/digital_twin_engine.d.ts.map +1 -1
- package/dist/engine/digital_twin_engine.js +20 -14
- package/dist/engine/digital_twin_engine.js.map +1 -1
- package/dist/engine/initializer.js +5 -11
- package/dist/engine/initializer.js.map +1 -1
- package/dist/engine/scheduler.d.ts.map +1 -1
- package/dist/engine/scheduler.js +10 -14
- package/dist/engine/scheduler.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/openapi/generator.d.ts +93 -0
- package/dist/openapi/generator.d.ts.map +1 -0
- package/dist/openapi/generator.js +293 -0
- package/dist/openapi/generator.js.map +1 -0
- package/dist/openapi/index.d.ts +9 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +9 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi/types.d.ts +182 -0
- package/dist/openapi/types.d.ts.map +1 -0
- package/dist/openapi/types.js +16 -0
- package/dist/openapi/types.js.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user_service.d.ts","sourceRoot":"","sources":["../../src/auth/user_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;gBAElC,EAAE,EAAE,eAAe;IAI/B;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"user_service.d.ts","sourceRoot":"","sources":["../../src/auth/user_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;gBAElC,EAAE,EAAE,eAAe;IAI/B;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAkDvC;;;;;OAKG;IACG,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IA8BxE;;OAEG;IACG,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAI9D;;OAEG;IACG,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAY9E;;OAEG;IACH,OAAO,CAAC,OAAO;IAOf;;OAEG;YACW,oBAAoB;IAgBlC;;OAEG;YACW,UAAU;IAuBxB;;OAEG;YACW,aAAa;IAoC3B;;OAEG;YACW,gBAAgB;CAqCjC"}
|
|
@@ -48,7 +48,6 @@ export class UserService {
|
|
|
48
48
|
*/
|
|
49
49
|
async initializeTables() {
|
|
50
50
|
const knex = this.getKnex();
|
|
51
|
-
console.log('Creating user management tables...');
|
|
52
51
|
// 1. Create roles table
|
|
53
52
|
if (!(await knex.schema.hasTable(this.rolesTable))) {
|
|
54
53
|
await knex.schema.createTable(this.rolesTable, table => {
|
|
@@ -58,7 +57,6 @@ export class UserService {
|
|
|
58
57
|
// Index pour les recherches par nom de rôle
|
|
59
58
|
table.index('name', 'roles_idx_name');
|
|
60
59
|
});
|
|
61
|
-
console.log('Roles table created');
|
|
62
60
|
}
|
|
63
61
|
// 2. Create users table
|
|
64
62
|
if (!(await knex.schema.hasTable(this.usersTable))) {
|
|
@@ -71,7 +69,6 @@ export class UserService {
|
|
|
71
69
|
table.index('keycloak_id', 'users_idx_keycloak_id');
|
|
72
70
|
table.index('created_at', 'users_idx_created_at');
|
|
73
71
|
});
|
|
74
|
-
console.log('Users table created');
|
|
75
72
|
}
|
|
76
73
|
// 3. Create user_roles junction table
|
|
77
74
|
if (!(await knex.schema.hasTable(this.userRolesTable))) {
|
|
@@ -88,9 +85,7 @@ export class UserService {
|
|
|
88
85
|
table.index('role_id', 'user_roles_idx_role_id');
|
|
89
86
|
table.index('user_id', 'user_roles_idx_user_id');
|
|
90
87
|
});
|
|
91
|
-
console.log('User_roles table created');
|
|
92
88
|
}
|
|
93
|
-
console.log('All user management tables ready');
|
|
94
89
|
}
|
|
95
90
|
/**
|
|
96
91
|
* Finds or creates a user and synchronizes their roles.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user_service.js","sourceRoot":"","sources":["../../src/auth/user_service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,WAAW;IAMpB,YAAY,EAAmB;QAJd,eAAU,GAAG,OAAO,CAAA;QACpB,eAAU,GAAG,OAAO,CAAA;QACpB,mBAAc,GAAG,YAAY,CAAA;QAG1C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QAClB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAE3B,
|
|
1
|
+
{"version":3,"file":"user_service.js","sourceRoot":"","sources":["../../src/auth/user_service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,WAAW;IAMpB,YAAY,EAAmB;QAJd,eAAU,GAAG,OAAO,CAAA;QACpB,eAAU,GAAG,OAAO,CAAA;QACpB,mBAAc,GAAG,YAAY,CAAA;QAG1C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QAClB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,cAAc,EAChC,GAAG,IAAI,CAAC,UAAU,aAAa,EAC/B,GAAG,IAAI,CAAC,UAAU,aAAa,EAC/B,GAAG,IAAI,CAAC,UAAU,oBAAoB,CACzC;aACA,KAAK,CAAC,GAAG,IAAI,CAAC,UAAU,KAAK,EAAE,MAAM,CAAC,CAMxC,CAAA;QAEH,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAA;QAEzC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;QACzB,MAAM,KAAK,GAAG,MAAM;aACf,MAAM,CAAC,CAAC,GAAG,EAA6C,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC;aAClF,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAE9B,OAAO;YACH,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,KAAK,EAAE,KAAK;YACZ,UAAU,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YACxC,UAAU,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;SAC3C,CAAA;IACL,CAAC;CACJ"}
|
|
@@ -4,6 +4,7 @@ import type { HttpMethod } from '../engine/endpoints.js';
|
|
|
4
4
|
import type { StorageService } from '../storage/storage_service.js';
|
|
5
5
|
import type { DatabaseAdapter, MetadataRow } from '../database/database_adapter.js';
|
|
6
6
|
import type { DataRecord } from '../types/data_record.js';
|
|
7
|
+
import type { OpenAPIDocumentable, OpenAPIComponentSpec } from '../openapi/types.js';
|
|
7
8
|
import { UserService } from '../auth/user_service.js';
|
|
8
9
|
/**
|
|
9
10
|
* Extended metadata row for assets with additional fields.
|
|
@@ -148,7 +149,7 @@ export interface UpdateAssetRequest {
|
|
|
148
149
|
*
|
|
149
150
|
* Each concrete AssetsManager creates its own table based on the configuration name.
|
|
150
151
|
*/
|
|
151
|
-
export declare abstract class AssetsManager implements Component, Servable {
|
|
152
|
+
export declare abstract class AssetsManager implements Component, Servable, OpenAPIDocumentable {
|
|
152
153
|
protected db: DatabaseAdapter;
|
|
153
154
|
protected storage: StorageService;
|
|
154
155
|
protected userService: UserService;
|
|
@@ -508,6 +509,15 @@ export declare abstract class AssetsManager implements Component, Servable {
|
|
|
508
509
|
handler: (...args: any[]) => any;
|
|
509
510
|
responseType?: string;
|
|
510
511
|
}>;
|
|
512
|
+
/**
|
|
513
|
+
* Returns the OpenAPI specification for this assets manager's endpoints.
|
|
514
|
+
*
|
|
515
|
+
* Generates documentation for all CRUD endpoints including batch operations.
|
|
516
|
+
* Can be overridden by subclasses for more detailed specifications.
|
|
517
|
+
*
|
|
518
|
+
* @returns {OpenAPIComponentSpec} OpenAPI paths, tags, and schemas for this assets manager
|
|
519
|
+
*/
|
|
520
|
+
getOpenAPISpec(): OpenAPIComponentSpec;
|
|
511
521
|
/**
|
|
512
522
|
* Handle single asset upload via HTTP POST.
|
|
513
523
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets_manager.d.ts","sourceRoot":"","sources":["../../src/components/assets_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"assets_manager.d.ts","sourceRoot":"","sources":["../../src/components/assets_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SA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AqEnD;;;;;;;;;;;;;OAaG;IACG,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAuDnD;;;;;;;;;;;;;;;;;;;OAmBG;IACG,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAcrD;;;;;;;;;;;;;;;;;;;OAmBG;IACG,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAerD;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAoCnD;;OAEG;IACG,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IA2CxD;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAwB7B;;;;;;OAMG;YACW,mBAAmB;IA6BjC;;OAEG;IACG,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAqCxD;;;;;;OAMG;YACW,mBAAmB;CAiCpC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApisixAuthParser } from '../auth/apisix_parser.js';
|
|
2
2
|
import { UserService } from '../auth/user_service.js';
|
|
3
|
+
import { AuthConfig } from '../auth/auth_config.js';
|
|
3
4
|
import { successResponse, errorResponse, badRequestResponse, unauthorizedResponse, forbiddenResponse, notFoundResponse, textResponse, fileResponse, multiStatusResponse, HttpStatus } from '../utils/http_responses.js';
|
|
4
5
|
import fs from 'fs/promises';
|
|
5
6
|
/**
|
|
@@ -208,6 +209,15 @@ export class AssetsManager {
|
|
|
208
209
|
* ```
|
|
209
210
|
*/
|
|
210
211
|
async authenticateRequest(req) {
|
|
212
|
+
// If auth is disabled, create an anonymous user
|
|
213
|
+
if (AuthConfig.isAuthDisabled()) {
|
|
214
|
+
const anonymousUser = {
|
|
215
|
+
id: AuthConfig.getAnonymousUserId(),
|
|
216
|
+
roles: []
|
|
217
|
+
};
|
|
218
|
+
const userRecord = await this.userService.findOrCreateUser(anonymousUser);
|
|
219
|
+
return { success: true, userRecord };
|
|
220
|
+
}
|
|
211
221
|
if (!ApisixAuthParser.hasValidAuth(req.headers || {})) {
|
|
212
222
|
return { success: false, response: unauthorizedResponse() };
|
|
213
223
|
}
|
|
@@ -233,6 +243,7 @@ export class AssetsManager {
|
|
|
233
243
|
source: req.body?.source,
|
|
234
244
|
is_public: req.body?.is_public,
|
|
235
245
|
filePath: req.file?.path,
|
|
246
|
+
fileBuffer: req.file?.buffer,
|
|
236
247
|
filename: req.file?.originalname || req.body?.filename
|
|
237
248
|
};
|
|
238
249
|
}
|
|
@@ -243,7 +254,8 @@ export class AssetsManager {
|
|
|
243
254
|
* @returns UploadValidationResult with validated data on success or error response on failure
|
|
244
255
|
*/
|
|
245
256
|
validateUploadFields(data) {
|
|
246
|
-
|
|
257
|
+
const hasFile = data.filePath || data.fileBuffer;
|
|
258
|
+
if (!hasFile || !data.description || !data.source) {
|
|
247
259
|
return {
|
|
248
260
|
success: false,
|
|
249
261
|
response: badRequestResponse('Missing required fields: description, source, file')
|
|
@@ -268,6 +280,7 @@ export class AssetsManager {
|
|
|
268
280
|
description: data.description,
|
|
269
281
|
source: data.source,
|
|
270
282
|
filePath: data.filePath,
|
|
283
|
+
fileBuffer: data.fileBuffer,
|
|
271
284
|
filename: data.filename,
|
|
272
285
|
is_public: data.is_public !== undefined ? Boolean(data.is_public) : true
|
|
273
286
|
}
|
|
@@ -302,6 +315,10 @@ export class AssetsManager {
|
|
|
302
315
|
* @returns DataResponse with error if not owner, undefined if valid
|
|
303
316
|
*/
|
|
304
317
|
validateOwnership(asset, userId) {
|
|
318
|
+
// Assets with no owner (null) can be modified by anyone
|
|
319
|
+
if (asset.owner_id === null) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
305
322
|
if (asset.owner_id !== userId) {
|
|
306
323
|
return forbiddenResponse('You can only modify your own assets');
|
|
307
324
|
}
|
|
@@ -759,6 +776,320 @@ export class AssetsManager {
|
|
|
759
776
|
}
|
|
760
777
|
];
|
|
761
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* Returns the OpenAPI specification for this assets manager's endpoints.
|
|
781
|
+
*
|
|
782
|
+
* Generates documentation for all CRUD endpoints including batch operations.
|
|
783
|
+
* Can be overridden by subclasses for more detailed specifications.
|
|
784
|
+
*
|
|
785
|
+
* @returns {OpenAPIComponentSpec} OpenAPI paths, tags, and schemas for this assets manager
|
|
786
|
+
*/
|
|
787
|
+
getOpenAPISpec() {
|
|
788
|
+
const config = this.getConfiguration();
|
|
789
|
+
const basePath = `/${config.endpoint}`;
|
|
790
|
+
const tagName = config.tags?.[0] || config.name;
|
|
791
|
+
return {
|
|
792
|
+
paths: {
|
|
793
|
+
[basePath]: {
|
|
794
|
+
get: {
|
|
795
|
+
summary: `List all ${config.name} assets`,
|
|
796
|
+
description: config.description,
|
|
797
|
+
tags: [tagName],
|
|
798
|
+
responses: {
|
|
799
|
+
'200': {
|
|
800
|
+
description: 'List of assets',
|
|
801
|
+
content: {
|
|
802
|
+
'application/json': {
|
|
803
|
+
schema: {
|
|
804
|
+
type: 'array',
|
|
805
|
+
items: { $ref: '#/components/schemas/AssetResponse' }
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
post: {
|
|
813
|
+
summary: `Upload a new ${config.name} asset`,
|
|
814
|
+
description: 'Upload a new asset file with metadata. Requires authentication.',
|
|
815
|
+
tags: [tagName],
|
|
816
|
+
security: [{ apiKeyAuth: [] }],
|
|
817
|
+
requestBody: {
|
|
818
|
+
required: true,
|
|
819
|
+
content: {
|
|
820
|
+
'multipart/form-data': {
|
|
821
|
+
schema: {
|
|
822
|
+
type: 'object',
|
|
823
|
+
required: ['file', 'description', 'source'],
|
|
824
|
+
properties: {
|
|
825
|
+
file: {
|
|
826
|
+
type: 'string',
|
|
827
|
+
format: 'binary',
|
|
828
|
+
description: 'The file to upload'
|
|
829
|
+
},
|
|
830
|
+
description: { type: 'string', description: 'Asset description' },
|
|
831
|
+
source: {
|
|
832
|
+
type: 'string',
|
|
833
|
+
format: 'uri',
|
|
834
|
+
description: 'Source URL for provenance'
|
|
835
|
+
},
|
|
836
|
+
is_public: {
|
|
837
|
+
type: 'boolean',
|
|
838
|
+
description: 'Whether asset is public (default: true)'
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
},
|
|
845
|
+
responses: {
|
|
846
|
+
'200': {
|
|
847
|
+
description: 'Asset uploaded successfully',
|
|
848
|
+
content: {
|
|
849
|
+
'application/json': {
|
|
850
|
+
schema: { $ref: '#/components/schemas/SuccessResponse' }
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
'400': { description: 'Bad request - missing or invalid fields' },
|
|
855
|
+
'401': { description: 'Unauthorized - authentication required' }
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
},
|
|
859
|
+
[`${basePath}/{id}`]: {
|
|
860
|
+
get: {
|
|
861
|
+
summary: `Get ${config.name} asset by ID`,
|
|
862
|
+
description: 'Returns the asset file content',
|
|
863
|
+
tags: [tagName],
|
|
864
|
+
parameters: [
|
|
865
|
+
{
|
|
866
|
+
name: 'id',
|
|
867
|
+
in: 'path',
|
|
868
|
+
required: true,
|
|
869
|
+
schema: { type: 'string' },
|
|
870
|
+
description: 'Asset ID'
|
|
871
|
+
}
|
|
872
|
+
],
|
|
873
|
+
responses: {
|
|
874
|
+
'200': {
|
|
875
|
+
description: 'Asset file content',
|
|
876
|
+
content: {
|
|
877
|
+
[config.contentType]: {
|
|
878
|
+
schema: { type: 'string', format: 'binary' }
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
'404': { description: 'Asset not found' }
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
put: {
|
|
886
|
+
summary: `Update ${config.name} asset metadata`,
|
|
887
|
+
description: 'Update asset description, source, or visibility. Requires authentication and ownership.',
|
|
888
|
+
tags: [tagName],
|
|
889
|
+
security: [{ apiKeyAuth: [] }],
|
|
890
|
+
parameters: [
|
|
891
|
+
{
|
|
892
|
+
name: 'id',
|
|
893
|
+
in: 'path',
|
|
894
|
+
required: true,
|
|
895
|
+
schema: { type: 'string' },
|
|
896
|
+
description: 'Asset ID'
|
|
897
|
+
}
|
|
898
|
+
],
|
|
899
|
+
requestBody: {
|
|
900
|
+
required: true,
|
|
901
|
+
content: {
|
|
902
|
+
'application/json': {
|
|
903
|
+
schema: {
|
|
904
|
+
type: 'object',
|
|
905
|
+
properties: {
|
|
906
|
+
description: { type: 'string' },
|
|
907
|
+
source: { type: 'string', format: 'uri' },
|
|
908
|
+
is_public: { type: 'boolean' }
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
responses: {
|
|
915
|
+
'200': {
|
|
916
|
+
description: 'Asset updated successfully',
|
|
917
|
+
content: {
|
|
918
|
+
'application/json': {
|
|
919
|
+
schema: { $ref: '#/components/schemas/SuccessResponse' }
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
'400': { description: 'Bad request' },
|
|
924
|
+
'401': { description: 'Unauthorized' },
|
|
925
|
+
'403': { description: 'Forbidden - not owner' },
|
|
926
|
+
'404': { description: 'Asset not found' }
|
|
927
|
+
}
|
|
928
|
+
},
|
|
929
|
+
delete: {
|
|
930
|
+
summary: `Delete ${config.name} asset`,
|
|
931
|
+
description: 'Delete an asset. Requires authentication and ownership.',
|
|
932
|
+
tags: [tagName],
|
|
933
|
+
security: [{ apiKeyAuth: [] }],
|
|
934
|
+
parameters: [
|
|
935
|
+
{
|
|
936
|
+
name: 'id',
|
|
937
|
+
in: 'path',
|
|
938
|
+
required: true,
|
|
939
|
+
schema: { type: 'string' },
|
|
940
|
+
description: 'Asset ID'
|
|
941
|
+
}
|
|
942
|
+
],
|
|
943
|
+
responses: {
|
|
944
|
+
'200': {
|
|
945
|
+
description: 'Asset deleted successfully',
|
|
946
|
+
content: {
|
|
947
|
+
'application/json': {
|
|
948
|
+
schema: { $ref: '#/components/schemas/SuccessResponse' }
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
},
|
|
952
|
+
'401': { description: 'Unauthorized' },
|
|
953
|
+
'403': { description: 'Forbidden - not owner' },
|
|
954
|
+
'404': { description: 'Asset not found' }
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
[`${basePath}/{id}/download`]: {
|
|
959
|
+
get: {
|
|
960
|
+
summary: `Download ${config.name} asset`,
|
|
961
|
+
description: 'Download the asset file with Content-Disposition header',
|
|
962
|
+
tags: [tagName],
|
|
963
|
+
parameters: [
|
|
964
|
+
{
|
|
965
|
+
name: 'id',
|
|
966
|
+
in: 'path',
|
|
967
|
+
required: true,
|
|
968
|
+
schema: { type: 'string' },
|
|
969
|
+
description: 'Asset ID'
|
|
970
|
+
}
|
|
971
|
+
],
|
|
972
|
+
responses: {
|
|
973
|
+
'200': {
|
|
974
|
+
description: 'Asset file download',
|
|
975
|
+
content: {
|
|
976
|
+
[config.contentType]: {
|
|
977
|
+
schema: { type: 'string', format: 'binary' }
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
'404': { description: 'Asset not found' }
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
},
|
|
985
|
+
[`${basePath}/batch`]: {
|
|
986
|
+
post: {
|
|
987
|
+
summary: `Batch upload ${config.name} assets`,
|
|
988
|
+
description: 'Upload multiple assets in one request. Files must be base64 encoded.',
|
|
989
|
+
tags: [tagName],
|
|
990
|
+
security: [{ apiKeyAuth: [] }],
|
|
991
|
+
requestBody: {
|
|
992
|
+
required: true,
|
|
993
|
+
content: {
|
|
994
|
+
'application/json': {
|
|
995
|
+
schema: {
|
|
996
|
+
type: 'object',
|
|
997
|
+
required: ['requests'],
|
|
998
|
+
properties: {
|
|
999
|
+
requests: {
|
|
1000
|
+
type: 'array',
|
|
1001
|
+
items: {
|
|
1002
|
+
type: 'object',
|
|
1003
|
+
required: ['file', 'description', 'source', 'filename'],
|
|
1004
|
+
properties: {
|
|
1005
|
+
file: {
|
|
1006
|
+
type: 'string',
|
|
1007
|
+
format: 'byte',
|
|
1008
|
+
description: 'Base64 encoded file'
|
|
1009
|
+
},
|
|
1010
|
+
filename: { type: 'string' },
|
|
1011
|
+
description: { type: 'string' },
|
|
1012
|
+
source: { type: 'string', format: 'uri' },
|
|
1013
|
+
is_public: { type: 'boolean' }
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
},
|
|
1022
|
+
responses: {
|
|
1023
|
+
'200': { description: 'All assets uploaded successfully' },
|
|
1024
|
+
'207': { description: 'Partial success - some uploads failed' },
|
|
1025
|
+
'400': { description: 'Bad request' },
|
|
1026
|
+
'401': { description: 'Unauthorized' }
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
delete: {
|
|
1030
|
+
summary: `Batch delete ${config.name} assets`,
|
|
1031
|
+
description: 'Delete multiple assets by IDs. Requires authentication and ownership.',
|
|
1032
|
+
tags: [tagName],
|
|
1033
|
+
security: [{ apiKeyAuth: [] }],
|
|
1034
|
+
requestBody: {
|
|
1035
|
+
required: true,
|
|
1036
|
+
content: {
|
|
1037
|
+
'application/json': {
|
|
1038
|
+
schema: {
|
|
1039
|
+
type: 'object',
|
|
1040
|
+
required: ['ids'],
|
|
1041
|
+
properties: {
|
|
1042
|
+
ids: {
|
|
1043
|
+
type: 'array',
|
|
1044
|
+
items: { type: 'string' },
|
|
1045
|
+
description: 'Array of asset IDs to delete'
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
responses: {
|
|
1053
|
+
'200': { description: 'All assets deleted successfully' },
|
|
1054
|
+
'207': { description: 'Partial success - some deletions failed' },
|
|
1055
|
+
'400': { description: 'Bad request' },
|
|
1056
|
+
'401': { description: 'Unauthorized' }
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
},
|
|
1061
|
+
tags: [
|
|
1062
|
+
{
|
|
1063
|
+
name: tagName,
|
|
1064
|
+
description: config.description
|
|
1065
|
+
}
|
|
1066
|
+
],
|
|
1067
|
+
schemas: {
|
|
1068
|
+
AssetResponse: {
|
|
1069
|
+
type: 'object',
|
|
1070
|
+
properties: {
|
|
1071
|
+
id: { type: 'integer' },
|
|
1072
|
+
name: { type: 'string' },
|
|
1073
|
+
date: { type: 'string', format: 'date-time' },
|
|
1074
|
+
contentType: { type: 'string' },
|
|
1075
|
+
description: { type: 'string' },
|
|
1076
|
+
source: { type: 'string' },
|
|
1077
|
+
owner_id: { type: 'integer', nullable: true },
|
|
1078
|
+
filename: { type: 'string' },
|
|
1079
|
+
is_public: { type: 'boolean' },
|
|
1080
|
+
url: { type: 'string' },
|
|
1081
|
+
download_url: { type: 'string' }
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1084
|
+
SuccessResponse: {
|
|
1085
|
+
type: 'object',
|
|
1086
|
+
properties: {
|
|
1087
|
+
message: { type: 'string' }
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
762
1093
|
/**
|
|
763
1094
|
* Handle single asset upload via HTTP POST.
|
|
764
1095
|
*
|
|
@@ -810,13 +1141,23 @@ export class AssetsManager {
|
|
|
810
1141
|
return validation.response;
|
|
811
1142
|
}
|
|
812
1143
|
const validData = validation.data;
|
|
813
|
-
//
|
|
1144
|
+
// Get file buffer from memory or read from temporary location
|
|
814
1145
|
let fileBuffer;
|
|
815
|
-
|
|
816
|
-
|
|
1146
|
+
if (validData.fileBuffer) {
|
|
1147
|
+
// Memory storage: buffer already available
|
|
1148
|
+
fileBuffer = validData.fileBuffer;
|
|
817
1149
|
}
|
|
818
|
-
|
|
819
|
-
|
|
1150
|
+
else if (validData.filePath) {
|
|
1151
|
+
// Disk storage: read from temp file
|
|
1152
|
+
try {
|
|
1153
|
+
fileBuffer = await this.readTempFile(validData.filePath);
|
|
1154
|
+
}
|
|
1155
|
+
catch (error) {
|
|
1156
|
+
return errorResponse(`Failed to read uploaded file: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
else {
|
|
1160
|
+
return badRequestResponse('No file data available');
|
|
820
1161
|
}
|
|
821
1162
|
// Upload asset and cleanup
|
|
822
1163
|
try {
|
|
@@ -828,10 +1169,14 @@ export class AssetsManager {
|
|
|
828
1169
|
file: fileBuffer,
|
|
829
1170
|
is_public: validData.is_public
|
|
830
1171
|
});
|
|
831
|
-
|
|
1172
|
+
if (validData.filePath) {
|
|
1173
|
+
await this.cleanupTempFile(validData.filePath);
|
|
1174
|
+
}
|
|
832
1175
|
}
|
|
833
1176
|
catch (error) {
|
|
834
|
-
|
|
1177
|
+
if (validData.filePath) {
|
|
1178
|
+
await this.cleanupTempFile(validData.filePath);
|
|
1179
|
+
}
|
|
835
1180
|
throw error;
|
|
836
1181
|
}
|
|
837
1182
|
return successResponse({ message: 'Asset uploaded successfully' });
|
|
@@ -1156,7 +1501,8 @@ export class AssetsManager {
|
|
|
1156
1501
|
results.push({ success: false, id, error: 'Asset not found' });
|
|
1157
1502
|
continue;
|
|
1158
1503
|
}
|
|
1159
|
-
if
|
|
1504
|
+
// Allow deletion if: owner is the current user OR asset has no owner
|
|
1505
|
+
if (asset.owner_id !== null && asset.owner_id !== userId) {
|
|
1160
1506
|
results.push({ success: false, id, error: 'You can only delete your own assets' });
|
|
1161
1507
|
continue;
|
|
1162
1508
|
}
|