@opengis/admin 0.3.47 → 0.3.49

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.
@@ -1,4 +1,4 @@
1
- import { _ as n, f as m } from "./import-file-7T94deeF.js";
1
+ import { _ as n, f as m } from "./import-file-jJLpE_mj.js";
2
2
  import { u as p } from "./user-B_2kh6ic.js";
3
3
  import { resolveComponent as f, openBlock as u, createElementBlock as d, createElementVNode as o, createBlock as h, createCommentVNode as b } from "vue";
4
4
  const x = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.3.47",
3
+ "version": "0.3.49",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -96,4 +96,4 @@
96
96
  "vitepress-plugin-tabs": "^0.5.0",
97
97
  "vitepress-sidebar": "1.30.2"
98
98
  }
99
- }
99
+ }
@@ -0,0 +1,53 @@
1
+ import path from 'node:path';
2
+
3
+ import { dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
4
+
5
+ import { uploadMultiPart } from '@opengis/fastify-file/utils.js';
6
+
7
+ export default async function widgetSet(req, reply) {
8
+ const { pg = pgClients.client, headers = {}, user = {}, params = {} } = req;
9
+
10
+ if (!params?.id) {
11
+ return reply.status(400).send('not enough params: id');
12
+ }
13
+
14
+ if (!pg.pk?.['crm.files']) {
15
+ return reply.status(404).send('table not found');
16
+ }
17
+
18
+ if (headers['content-type']?.split?.(';')?.shift?.() !== 'multipart/form-data') {
19
+ return reply.status(400).send('invalid payload content type');
20
+ }
21
+
22
+ const file = await uploadMultiPart(req);
23
+ const extName = path.extname(file.filepath).slice(1).toLowerCase();
24
+
25
+ const data = {
26
+ uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
27
+ file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
28
+ ext: extName,
29
+ size: file?.size,
30
+ file_status: 1,
31
+ uid: user?.uid || 1,
32
+ };
33
+
34
+ const result = await dataUpdate({
35
+ pg,
36
+ table: 'crm.files',
37
+ id: params.id,
38
+ data,
39
+ uid: user?.uid,
40
+ });
41
+
42
+ if (!result?.file_id) {
43
+ return reply.status(404).send('file not found');
44
+ }
45
+
46
+ return reply.status(200).send({
47
+ rowCount: 1,
48
+ data: result,
49
+ command: 'UPLOAD',
50
+ id: result?.file_id,
51
+ entity_id: result?.entity_id,
52
+ });
53
+ }
@@ -21,7 +21,7 @@ const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi']
21
21
 
22
22
  export default async function widgetSet(req, reply) {
23
23
  const {
24
- pg, params = {}, session = {}, body = {}, user = {},
24
+ pg, params = {}, session = {}, headers = {}, body = {}, user = {},
25
25
  } = req;
26
26
  const { type, id, objectid } = params;
27
27
 
@@ -36,7 +36,7 @@ export default async function widgetSet(req, reply) {
36
36
  const table = tableList[type];
37
37
 
38
38
  // dsadasdad
39
- if (['gallery', 'file'].includes(type) && req.headers['content-type'].split(';').shift() === "multipart/form-data") {
39
+ if (['gallery', 'file'].includes(type) && headers['content-type']?.split?.(';')?.shift?.() === "multipart/form-data") {
40
40
  const file = await uploadMultiPart(req);
41
41
  const extName = path.extname(file.filepath).slice(1).toLowerCase();
42
42
 
@@ -3,6 +3,7 @@ import { addHook } from '@opengis/fastify-table/utils.js';
3
3
  import widgetDel from './controllers/widget.del.js';
4
4
  import widgetSet from './controllers/widget.set.js';
5
5
  import widgetGet from './controllers/widget.get.js';
6
+ import fileEdit from './controllers/file.edit.js';
6
7
 
7
8
  import onWidgetSet from './hook/onWidgetSet.js';
8
9
 
@@ -11,6 +12,7 @@ import { tableSchema } from './schema.js';
11
12
  export default async function route(fastify) {
12
13
  fastify.delete(`/widget/:type/:objectid/:id`, { scheme: tableSchema }, widgetDel);
13
14
  fastify.post(`/widget/:type/:objectid/:id?`, { scheme: tableSchema }, widgetSet);
15
+ fastify.put(`/file-edit/:id`, { scheme: tableSchema }, fileEdit);
14
16
  fastify.get(`/widget/:type/:objectid`, { config: { policy: ['public'] }, scheme: tableSchema }, widgetGet);
15
17
  addHook('onWidgetSet', onWidgetSet);
16
18
  }