adminizer 4.3.0-build.103 → 4.3.0-build.105
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/assets/{add-1E1UsMVZ.js → add-GU2aUgZb.js} +1 -1
- package/assets/{add-form-CGa9QbwE.js → add-form-eJEMdv04.js} +1 -1
- package/assets/app.js +2 -2
- package/assets/{catalog-B9hdop59.js → catalog-CZ_wUlq2.js} +1 -1
- package/assets/{field-renderer-4obZ_jUo.js → field-renderer-BhrQ1BlC.js} +2 -2
- package/assets/{form-qyuRZEIC.js → form-CbwqHa8P.js} +1 -1
- package/assets/{form-DmBOE8Za.js → form-DMebrwNT.js} +1 -1
- package/assets/{home-DxhSEMhE.js → home-GaTaODxj.js} +2 -2
- package/assets/manifest.json +16 -16
- package/assets/{media-manager-UQT6RhI8.js → media-manager-DyP_37fD.js} +1 -1
- package/controllers/add.js +1 -1
- package/controllers/edit.js +6 -4
- package/controllers/form.js +7 -6
- package/controllers/media-manager/ThumbController.js +1 -1
- package/controllers/media-manager/mediaManagerApi.js +1 -2
- package/controllers/view.js +5 -3
- package/helpers/inertiaAddHelper.js +1 -2
- package/helpers/inertiaFromHelper.js +1 -2
- package/lib/Adminizer.d.ts +2 -0
- package/lib/Adminizer.js +3 -0
- package/lib/media-manager/AbstractMediaManager.d.ts +5 -3
- package/lib/media-manager/DefaultMediaManager.d.ts +3 -3
- package/lib/media-manager/DefaultMediaManager.js +17 -12
- package/lib/media-manager/MediaManagerHandler.d.ts +3 -3
- package/lib/media-manager/MediaManagerHandler.js +3 -3
- package/lib/media-manager/Thumb.d.ts +2 -1
- package/lib/media-manager/Thumb.js +2 -3
- package/lib/media-manager/helpers/MediaManagerHelper.d.ts +7 -2
- package/lib/media-manager/helpers/MediaManagerHelper.js +12 -8
- package/package.json +1 -1
- package/system/bindMediaManager.js +1 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as h,ak as kn,al as In,g as Q,w as _i,x as $i,Y as Ln,y as Wi,z as ht,a8 as Mr,a9 as Tr,aa as jr,ab as Rr,am as zn,an as Yt,B as J,a1 as Pn,a2 as Bn,a3 as _t,a4 as oe,a5 as Xn,a6 as se,I as qt,L as Ct,a as bt,ao as Hi,ap as Ui,aq as Fi,a0 as Vi,ar as Gi,f as fr,aj as Ki,D as qi,h as Ji,i as Zi,k as Qr,as as Qi}from"./app.js";import{r as g,e as B}from"./monaco-ICtx6xoc.js";import{r as mt}from"./handsontable-PVakPtJV.js";import{I as Yn,P as $t,p as ea}from"./field-renderer-
|
|
1
|
+
import{j as h,ak as kn,al as In,g as Q,w as _i,x as $i,Y as Ln,y as Wi,z as ht,a8 as Mr,a9 as Tr,aa as jr,ab as Rr,am as zn,an as Yt,B as J,a1 as Pn,a2 as Bn,a3 as _t,a4 as oe,a5 as Xn,a6 as se,I as qt,L as Ct,a as bt,ao as Hi,ap as Ui,aq as Fi,a0 as Vi,ar as Gi,f as fr,aj as Ki,D as qi,h as Ji,i as Zi,k as Qr,as as Qi}from"./app.js";import{r as g,e as B}from"./monaco-ICtx6xoc.js";import{r as mt}from"./handsontable-PVakPtJV.js";import{I as Yn,P as $t,p as ea}from"./field-renderer-BhrQ1BlC.js";import{T as ta,a as ra,b as Ke,c as qe}from"./tabs-BK_5wdPA.js";import{d as na}from"./jsoneditor-D95dIAP2.js";import"./vendor-wzZzN_Jv.js";import"./dynamic-controls-BOYmRX_z.js";function ia(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return g.useMemo(()=>n=>{e.forEach(a=>a(n))},e)}const Jt=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function it(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function Or(t){return"nodeType"in t}function ee(t){var e,r;return t?it(t)?t:Or(t)&&(e=(r=t.ownerDocument)==null?void 0:r.defaultView)!=null?e:window:window}function Ar(t){const{Document:e}=ee(t);return t instanceof e}function Tt(t){return it(t)?!1:t instanceof ee(t).HTMLElement}function _n(t){return t instanceof ee(t).SVGElement}function at(t){return t?it(t)?t.document:Or(t)?Ar(t)?t:Tt(t)||_n(t)?t.ownerDocument:document:document:document}const pe=Jt?g.useLayoutEffect:g.useEffect;function Zt(t){const e=g.useRef(t);return pe(()=>{e.current=t}),g.useCallback(function(){for(var r=arguments.length,n=new Array(r),a=0;a<r;a++)n[a]=arguments[a];return e.current==null?void 0:e.current(...n)},[])}function aa(){const t=g.useRef(null),e=g.useCallback((n,a)=>{t.current=setInterval(n,a)},[]),r=g.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,r]}function St(t,e){e===void 0&&(e=[t]);const r=g.useRef(t);return pe(()=>{r.current!==t&&(r.current=t)},e),r}function jt(t,e){const r=g.useRef();return g.useMemo(()=>{const n=t(r.current);return r.current=n,n},[...e])}function Wt(t){const e=Zt(t),r=g.useRef(null),n=g.useCallback(a=>{a!==r.current&&(e==null||e(a,r.current)),r.current=a},[]);return[r,n]}function Ht(t){const e=g.useRef();return g.useEffect(()=>{e.current=t},[t]),e.current}let or={};function Rt(t,e){return g.useMemo(()=>{if(e)return e;const r=or[t]==null?0:or[t]+1;return or[t]=r,t+"-"+r},[t,e])}function $n(t){return function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),a=1;a<r;a++)n[a-1]=arguments[a];return n.reduce((i,o)=>{const s=Object.entries(o);for(const[d,l]of s){const c=i[d];c!=null&&(i[d]=c+t*l)}return i},{...e})}}const et=$n(1),Et=$n(-1);function oa(t){return"clientX"in t&&"clientY"in t}function Ot(t){if(!t)return!1;const{KeyboardEvent:e}=ee(t.target);return e&&t instanceof e}function sa(t){if(!t)return!1;const{TouchEvent:e}=ee(t.target);return e&&t instanceof e}function Ut(t){if(sa(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:r}=t.touches[0];return{x:e,y:r}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:r}=t.changedTouches[0];return{x:e,y:r}}}return oa(t)?{x:t.clientX,y:t.clientY}:null}const ye=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:r}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(r?Math.round(r):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:r}=t;return"scaleX("+e+") scaleY("+r+")"}},Transform:{toString(t){if(t)return[ye.Translate.toString(t),ye.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:r,easing:n}=t;return e+" "+r+"ms "+n}}}),en="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function la(t){return t.matches(en)?t:t.querySelector(en)}const ca={display:"none"};function da(t){let{id:e,value:r}=t;return B.createElement("div",{id:e,style:ca},r)}function ua(t){let{id:e,announcement:r,ariaLiveType:n="assertive"}=t;const a={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return B.createElement("div",{id:e,style:a,role:"status","aria-live":n,"aria-atomic":!0},r)}function ha(){const[t,e]=g.useState("");return{announce:g.useCallback(n=>{n!=null&&e(n)},[]),announcement:t}}const Wn=g.createContext(null);function fa(t){const e=g.useContext(Wn);g.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of <DndContext>");return e(t)},[t,e])}function pa(){const[t]=g.useState(()=>new Set),e=g.useCallback(n=>(t.add(n),()=>t.delete(n)),[t]);return[g.useCallback(n=>{let{type:a,event:i}=n;t.forEach(o=>{var s;return(s=o[a])==null?void 0:s.call(o,i)})},[t]),e]}const ga={draggable:`
|
|
2
2
|
To pick up a draggable item, press the space bar.
|
|
3
3
|
While dragging, use the arrow keys to move the item.
|
|
4
4
|
Press space again to drop the item in its new position, or press escape to cancel.
|
package/controllers/add.js
CHANGED
|
@@ -88,7 +88,7 @@ export default async function add(req, res) {
|
|
|
88
88
|
try {
|
|
89
89
|
let record = await entity.model.create(reqData, dataAccessor);
|
|
90
90
|
// save associations media to json
|
|
91
|
-
await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, record.id);
|
|
91
|
+
await saveRelationsMediaManager(req.adminizer, fields, rawReqData, entity.model.identity, record.id);
|
|
92
92
|
Adminizer.log.debug(`A new record was created: `, record);
|
|
93
93
|
if (req.body.jsonPopupCatalog) {
|
|
94
94
|
dataAccessor = new DataAccessor(req.adminizer, req.user, entity, "edit");
|
package/controllers/edit.js
CHANGED
|
@@ -112,7 +112,7 @@ export default async function edit(req, res) {
|
|
|
112
112
|
}
|
|
113
113
|
try {
|
|
114
114
|
let newRecord = await entity.model.update(params, reqData, dataAccessor);
|
|
115
|
-
await saveRelationsMediaManager(fields, rawReqData, entity.model.identity, newRecord[0].id);
|
|
115
|
+
await saveRelationsMediaManager(req.adminizer, fields, rawReqData, entity.model.identity, newRecord[0].id);
|
|
116
116
|
Adminizer.log.debug(`Record was updated: `, newRecord);
|
|
117
117
|
if (req.body.jsonPopupCatalog) {
|
|
118
118
|
return res.json({ record: newRecord });
|
|
@@ -142,9 +142,11 @@ export default async function edit(req, res) {
|
|
|
142
142
|
for (const field of Object.keys(fields)) {
|
|
143
143
|
let fieldConfigConfig = fields[field].config;
|
|
144
144
|
if (fieldConfigConfig.type === 'mediamanager') {
|
|
145
|
-
record[field] = await getRelationsMediaManager({
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
record[field] = await getRelationsMediaManager(req.adminizer, {
|
|
146
|
+
mediaManagerId: fieldConfigConfig.options?.id ?? "default",
|
|
147
|
+
model: entity.model.modelname,
|
|
148
|
+
widgetName: field,
|
|
149
|
+
modelId: id
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
152
|
}
|
package/controllers/form.js
CHANGED
|
@@ -2,7 +2,6 @@ import { FormHelper } from "../helpers/formHelper";
|
|
|
2
2
|
import { Adminizer } from "../lib/Adminizer";
|
|
3
3
|
import inertiaFormHelper from "../helpers/inertiaFromHelper";
|
|
4
4
|
import { getRelationsMediaManager } from "../lib/media-manager/helpers/MediaManagerHelper";
|
|
5
|
-
import { MediaManagerHandler } from "../lib/media-manager/MediaManagerHandler";
|
|
6
5
|
export default async function form(req, res) {
|
|
7
6
|
let slug = req.params.slug;
|
|
8
7
|
// Check slug
|
|
@@ -45,9 +44,9 @@ export default async function form(req, res) {
|
|
|
45
44
|
}
|
|
46
45
|
if (form[key].type === "mediamanager") {
|
|
47
46
|
let options = form[key].options;
|
|
48
|
-
let mediaManager =
|
|
47
|
+
let mediaManager = req.adminizer.mediaManagerHandler.get(options?.id ?? "default");
|
|
49
48
|
if (req.body[key])
|
|
50
|
-
await mediaManager.setRelations(req.body[key],
|
|
49
|
+
await mediaManager.setRelations(req.body[key], `${slug}_${key}`, 0, key);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
for (let field of Object.keys(req.body)) {
|
|
@@ -63,9 +62,11 @@ export default async function form(req, res) {
|
|
|
63
62
|
for (let key of Object.keys(form)) {
|
|
64
63
|
try {
|
|
65
64
|
if (form[key].type === 'mediamanager') {
|
|
66
|
-
form[key].value = await getRelationsMediaManager({
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
form[key].value = await getRelationsMediaManager(req.adminizer, {
|
|
66
|
+
mediaManagerId: form[key].options?.id ?? "default",
|
|
67
|
+
model: `${slug}_${key}`,
|
|
68
|
+
widgetName: key,
|
|
69
|
+
modelId: 0
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
else {
|
|
@@ -5,6 +5,6 @@ export async function thumbController(req, res) {
|
|
|
5
5
|
const managerId = req.query.managerId;
|
|
6
6
|
if (method === 'GET') {
|
|
7
7
|
res.setHeader('Content-Type', 'image/webp');
|
|
8
|
-
res.send(await MediaManagerThumb.getThumb(id, managerId));
|
|
8
|
+
res.send(await MediaManagerThumb.getThumb(id, managerId, req.adminizer));
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { MediaManagerHandler } from "../../lib/media-manager/MediaManagerHandler";
|
|
2
1
|
import { MediaManagerAdapter } from "./mediaManagerAdapter";
|
|
3
2
|
export async function mediaManagerController(req, res) {
|
|
4
3
|
const method = req.method.toUpperCase();
|
|
@@ -16,7 +15,7 @@ export async function mediaManagerController(req, res) {
|
|
|
16
15
|
if (!id) {
|
|
17
16
|
return res.sendStatus(404);
|
|
18
17
|
}
|
|
19
|
-
const _manager =
|
|
18
|
+
const _manager = req.adminizer.mediaManagerHandler.get(id);
|
|
20
19
|
const manager = new MediaManagerAdapter(_manager);
|
|
21
20
|
if (method === 'GET') {
|
|
22
21
|
if (req.query._method === 'getLocales') {
|
package/controllers/view.js
CHANGED
|
@@ -86,9 +86,11 @@ export default async function view(req, res) {
|
|
|
86
86
|
for (const field of Object.keys(fields)) {
|
|
87
87
|
let fieldConfigConfig = fields[field].config;
|
|
88
88
|
if (fieldConfigConfig.type === 'mediamanager') {
|
|
89
|
-
record[field] = await getRelationsMediaManager({
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
record[field] = await getRelationsMediaManager(req.adminizer, {
|
|
90
|
+
mediaManagerId: fieldConfigConfig.options?.id ?? "default",
|
|
91
|
+
model: entity.model.modelname,
|
|
92
|
+
widgetName: field,
|
|
93
|
+
modelId: req.params.id
|
|
92
94
|
});
|
|
93
95
|
}
|
|
94
96
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import inertiaActionsHelper from "./inertiaActionsHelper";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { isObject } from "./JsUtils";
|
|
4
|
-
import { MediaManagerHandler } from "../lib/media-manager/MediaManagerHandler";
|
|
5
4
|
export default function inertiaAddHelper(req, entity, fields, record, view = false) {
|
|
6
5
|
const actionType = 'add';
|
|
7
6
|
let props = {
|
|
@@ -107,7 +106,7 @@ export default function inertiaAddHelper(req, entity, fields, record, view = fal
|
|
|
107
106
|
if (type === 'mediamanager') {
|
|
108
107
|
const mConfig = field.config;
|
|
109
108
|
const mOptions = mConfig?.options;
|
|
110
|
-
const mediaManager =
|
|
109
|
+
const mediaManager = req.adminizer.mediaManagerHandler.get(mOptions.id || 'default');
|
|
111
110
|
if (!mediaManager) {
|
|
112
111
|
options = {};
|
|
113
112
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { inputText, setSelectMany, getControlsOptions } from "./inertiaAddHelper";
|
|
2
|
-
import { MediaManagerHandler } from "../lib/media-manager/MediaManagerHandler";
|
|
3
2
|
export default function inertiaFormHelper(req, postLink, formData) {
|
|
4
3
|
let props = {
|
|
5
4
|
fields: [],
|
|
@@ -74,7 +73,7 @@ export default function inertiaFormHelper(req, postLink, formData) {
|
|
|
74
73
|
}
|
|
75
74
|
if (type === 'mediamanager') {
|
|
76
75
|
const mOptions = field.options;
|
|
77
|
-
const mediaManager =
|
|
76
|
+
const mediaManager = req.adminizer.mediaManagerHandler.get(mOptions.id || 'default');
|
|
78
77
|
if (!mediaManager) {
|
|
79
78
|
options = {};
|
|
80
79
|
}
|
package/lib/Adminizer.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { ControlsHandler } from "./controls/ControlsHandler";
|
|
|
14
14
|
import { CatalogHandler } from "./catalog/CatalogHandler";
|
|
15
15
|
import { NotificationHandler } from './notifications/NotificationHandler';
|
|
16
16
|
import { INotification } from "../interfaces/types";
|
|
17
|
+
import { MediaManagerHandler } from "./media-manager/MediaManagerHandler";
|
|
17
18
|
export declare class Adminizer {
|
|
18
19
|
/**
|
|
19
20
|
* If you convey this default Middleware, it will add it to the very top of the router,
|
|
@@ -34,6 +35,7 @@ export declare class Adminizer {
|
|
|
34
35
|
vite: ViteDevServer;
|
|
35
36
|
controlsHandler: ControlsHandler;
|
|
36
37
|
catalogHandler: CatalogHandler;
|
|
38
|
+
mediaManagerHandler: MediaManagerHandler;
|
|
37
39
|
jwtSecret: string;
|
|
38
40
|
static logger: winston.Logger;
|
|
39
41
|
constructor(ormAdapters: AbstractAdapter[]);
|
package/lib/Adminizer.js
CHANGED
|
@@ -30,6 +30,7 @@ import { ControlsHandler } from "./controls/ControlsHandler";
|
|
|
30
30
|
import { CatalogHandler } from "./catalog/CatalogHandler";
|
|
31
31
|
import { v4 as uuid } from "uuid";
|
|
32
32
|
import { bindNotifications } from "../system/bindNotifications";
|
|
33
|
+
import { MediaManagerHandler } from "./media-manager/MediaManagerHandler";
|
|
33
34
|
export class Adminizer {
|
|
34
35
|
// Preconfigures
|
|
35
36
|
/**
|
|
@@ -52,6 +53,7 @@ export class Adminizer {
|
|
|
52
53
|
vite;
|
|
53
54
|
controlsHandler;
|
|
54
55
|
catalogHandler;
|
|
56
|
+
mediaManagerHandler;
|
|
55
57
|
// Constants
|
|
56
58
|
jwtSecret = process.env.JWT_SECRET ?? uuid();
|
|
57
59
|
static logger = winston.createLogger({
|
|
@@ -195,6 +197,7 @@ export class Adminizer {
|
|
|
195
197
|
this.menuHelper = new MenuHelper(this.config);
|
|
196
198
|
this.widgetHandler = new WidgetHandler(this);
|
|
197
199
|
this.catalogHandler = new CatalogHandler();
|
|
200
|
+
this.mediaManagerHandler = new MediaManagerHandler();
|
|
198
201
|
bindExpressUtils(this.app);
|
|
199
202
|
bindReqFunctions(this);
|
|
200
203
|
// Bind assets
|
|
@@ -36,8 +36,10 @@ export interface MediaManagerWidgetClientItem extends MediaManagerWidgetItem {
|
|
|
36
36
|
url?: string;
|
|
37
37
|
}
|
|
38
38
|
export interface MediaManagerWidgetJSON {
|
|
39
|
-
list: MediaManagerWidgetItem[];
|
|
40
39
|
mediaManagerId: string;
|
|
40
|
+
model: string;
|
|
41
|
+
widgetName: string;
|
|
42
|
+
modelId: string | number;
|
|
41
43
|
}
|
|
42
44
|
export interface MediaManagerWidgetData {
|
|
43
45
|
id: string;
|
|
@@ -207,8 +209,8 @@ export declare abstract class AbstractMediaManager {
|
|
|
207
209
|
/**
|
|
208
210
|
* widget Id in the model in which the mediafile was added
|
|
209
211
|
*/
|
|
210
|
-
modelId:
|
|
211
|
-
abstract
|
|
212
|
+
modelId: number, widgetName: string): Promise<void>;
|
|
213
|
+
abstract getRelations(model: string, widgetName: string, modelId: string | number): Promise<MediaManagerWidgetClientItem[]>;
|
|
212
214
|
/**
|
|
213
215
|
* Search all items.
|
|
214
216
|
* If not this.allowSearch = true then it will not come here
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractMediaManager, MediaManagerItem, File,
|
|
1
|
+
import { AbstractMediaManager, MediaManagerItem, File, MediaManagerWidgetData, MediaManagerWidgetClientItem, SortCriteria } from "./AbstractMediaManager";
|
|
2
2
|
import { Adminizer } from "../Adminizer";
|
|
3
3
|
export declare class DefaultMediaManager extends AbstractMediaManager {
|
|
4
4
|
readonly itemTypes: File<MediaManagerItem>[];
|
|
@@ -12,6 +12,6 @@ export declare class DefaultMediaManager extends AbstractMediaManager {
|
|
|
12
12
|
next: boolean;
|
|
13
13
|
}>;
|
|
14
14
|
searchAll(s: string, group: string): Promise<MediaManagerItem[]>;
|
|
15
|
-
setRelations(data: MediaManagerWidgetData[], model: string, modelId:
|
|
16
|
-
|
|
15
|
+
setRelations(data: MediaManagerWidgetData[], model: string, modelId: number, widgetName: string): Promise<void>;
|
|
16
|
+
getRelations(model: string, widgetName: string, modelId: string | number): Promise<MediaManagerWidgetClientItem[]>;
|
|
17
17
|
}
|
|
@@ -57,7 +57,7 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
57
57
|
}
|
|
58
58
|
async setRelations(data, model, modelId, widgetName) {
|
|
59
59
|
let modelAssociations = await this.adminizer.modelHandler.model.get(this.modelAssoc)["_find"]({
|
|
60
|
-
where: { modelId: modelId, model: model, widgetName: widgetName },
|
|
60
|
+
where: { modelId: modelId, model: model.toLowerCase(), widgetName: widgetName },
|
|
61
61
|
});
|
|
62
62
|
for (const modelAssociation of modelAssociations) {
|
|
63
63
|
const q = {};
|
|
@@ -69,7 +69,7 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
69
69
|
for (const [key, widgetItem] of data.entries()) {
|
|
70
70
|
await this.adminizer.modelHandler.model.get(this.modelAssoc)["_create"]({
|
|
71
71
|
mediaManagerId: this.id,
|
|
72
|
-
model: model,
|
|
72
|
+
model: model.toLowerCase(),
|
|
73
73
|
modelId: modelId,
|
|
74
74
|
[fieldName]: widgetItem.id,
|
|
75
75
|
widgetName: widgetName,
|
|
@@ -77,18 +77,23 @@ export class DefaultMediaManager extends AbstractMediaManager {
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
async
|
|
80
|
+
async getRelations(model, widgetName, modelId) {
|
|
81
81
|
let widgetItems = [];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
const fieldName = this.adminizer.ormAdapters[0].ormType === 'sequelize' ? 'fileRef' : 'file';
|
|
83
|
+
let files = await this.adminizer.modelHandler.model.get(this.modelAssoc)['_find']({
|
|
84
|
+
where: {
|
|
85
|
+
model: model.toLowerCase(),
|
|
86
|
+
widgetName: widgetName,
|
|
87
|
+
modelId: +modelId
|
|
88
|
+
},
|
|
89
|
+
sort: "sortOrder ASC"
|
|
90
|
+
}, { populate: [[fieldName, {}]] });
|
|
91
|
+
for (const file of files) {
|
|
87
92
|
widgetItems.push({
|
|
88
|
-
id: file.id,
|
|
89
|
-
mimeType: file.mimeType,
|
|
90
|
-
url: file.url,
|
|
91
|
-
variants:
|
|
93
|
+
id: file[fieldName].id,
|
|
94
|
+
mimeType: file[fieldName].mimeType,
|
|
95
|
+
url: file[fieldName].url,
|
|
96
|
+
variants: []
|
|
92
97
|
});
|
|
93
98
|
}
|
|
94
99
|
return widgetItems;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractMediaManager } from "./AbstractMediaManager";
|
|
2
2
|
export declare class MediaManagerHandler {
|
|
3
|
-
private
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
private managers;
|
|
4
|
+
add(manager: AbstractMediaManager): void;
|
|
5
|
+
get(id: string): AbstractMediaManager;
|
|
6
6
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Adminizer } from "../Adminizer";
|
|
2
2
|
export class MediaManagerHandler {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
managers = [];
|
|
4
|
+
add(manager) {
|
|
5
5
|
this.managers.push(manager);
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
get(id) {
|
|
8
8
|
let instance = this.managers.find(e => e.id === id);
|
|
9
9
|
/**
|
|
10
10
|
* ✨ We magically get one
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Adminizer } from "../Adminizer";
|
|
1
2
|
export declare class MediaManagerThumb {
|
|
2
|
-
static getThumb(id: string, managerId: string): Promise<Buffer<ArrayBufferLike>>;
|
|
3
|
+
static getThumb(id: string, managerId: string, adminizer: Adminizer): Promise<Buffer<ArrayBufferLike>>;
|
|
3
4
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import sharp from "sharp";
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
|
-
import { MediaManagerHandler } from "./MediaManagerHandler";
|
|
4
3
|
export class MediaManagerThumb {
|
|
5
|
-
static async getThumb(id, managerId) {
|
|
4
|
+
static async getThumb(id, managerId, adminizer) {
|
|
6
5
|
const fileExists = async (path) => !!(await fs.stat(path).catch(e => false));
|
|
7
|
-
const manager =
|
|
6
|
+
const manager = adminizer.mediaManagerHandler.get(managerId);
|
|
8
7
|
const path = await manager.getOrigin(id);
|
|
9
8
|
const baseThumbPath = `${process.cwd()}/.tmp/thumbs`;
|
|
10
9
|
await fs.mkdir(baseThumbPath, { recursive: true });
|
|
@@ -11,19 +11,24 @@ type PostParams = Record<string, string | number | boolean | object | string[] |
|
|
|
11
11
|
export declare function randomFileName(filenameOrig: string, type: string, prefix: boolean): string;
|
|
12
12
|
/**
|
|
13
13
|
* Save media manager relations to database.
|
|
14
|
+
* @param adminizer
|
|
14
15
|
* @param fields
|
|
15
16
|
* @param reqData
|
|
16
17
|
* @param model
|
|
17
18
|
* @param recordId
|
|
18
19
|
*/
|
|
19
|
-
export declare function saveRelationsMediaManager(fields: Fields, reqData: PostParams, model: string, recordId:
|
|
20
|
+
export declare function saveRelationsMediaManager(adminizer: Adminizer, fields: Fields, reqData: PostParams, model: string, recordId: number): Promise<void>;
|
|
20
21
|
/**
|
|
21
22
|
* Get realtions
|
|
23
|
+
* @param adminizer
|
|
22
24
|
* @param data
|
|
25
|
+
* @param model
|
|
26
|
+
* @param widgetName
|
|
23
27
|
*/
|
|
24
|
-
export declare function getRelationsMediaManager(data: MediaManagerWidgetJSON): Promise<import("../AbstractMediaManager").MediaManagerWidgetClientItem[]>;
|
|
28
|
+
export declare function getRelationsMediaManager(adminizer: Adminizer, data: MediaManagerWidgetJSON): Promise<import("../AbstractMediaManager").MediaManagerWidgetClientItem[]>;
|
|
25
29
|
/**
|
|
26
30
|
* Delate Ralations
|
|
31
|
+
* @param adminizer
|
|
27
32
|
* @param model
|
|
28
33
|
* @param record
|
|
29
34
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { MediaManagerHandler } from "../MediaManagerHandler";
|
|
2
1
|
/**
|
|
3
2
|
* Create a random file name with prefix and type. If prefix is true, the file name will be prefixed with a random string.
|
|
4
3
|
* @param filenameOrig
|
|
@@ -13,32 +12,37 @@ export function randomFileName(filenameOrig, type, prefix) {
|
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* Save media manager relations to database.
|
|
15
|
+
* @param adminizer
|
|
16
16
|
* @param fields
|
|
17
17
|
* @param reqData
|
|
18
18
|
* @param model
|
|
19
19
|
* @param recordId
|
|
20
20
|
*/
|
|
21
|
-
export async function saveRelationsMediaManager(fields, reqData, model, recordId) {
|
|
21
|
+
export async function saveRelationsMediaManager(adminizer, fields, reqData, model, recordId) {
|
|
22
22
|
for (let prop in reqData) {
|
|
23
23
|
let fieldConfigConfig = fields[prop].config;
|
|
24
24
|
let options = fieldConfigConfig.options;
|
|
25
25
|
if (fieldConfigConfig.type === 'mediamanager') {
|
|
26
26
|
let data = reqData[prop];
|
|
27
|
-
let mediaManager =
|
|
27
|
+
let mediaManager = adminizer.mediaManagerHandler.get(options?.id ?? 'default');
|
|
28
28
|
await mediaManager.setRelations(data, model, recordId, prop);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Get realtions
|
|
34
|
+
* @param adminizer
|
|
34
35
|
* @param data
|
|
36
|
+
* @param model
|
|
37
|
+
* @param widgetName
|
|
35
38
|
*/
|
|
36
|
-
export async function getRelationsMediaManager(data) {
|
|
37
|
-
let mediaManager =
|
|
38
|
-
return await mediaManager.
|
|
39
|
+
export async function getRelationsMediaManager(adminizer, data) {
|
|
40
|
+
let mediaManager = adminizer.mediaManagerHandler.get(data.mediaManagerId);
|
|
41
|
+
return await mediaManager.getRelations(data.model, data.widgetName, data.modelId);
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
44
|
* Delate Ralations
|
|
45
|
+
* @param adminizer
|
|
42
46
|
* @param model
|
|
43
47
|
* @param record
|
|
44
48
|
*/
|
|
@@ -48,9 +52,9 @@ export async function deleteRelationsMediaManager(adminizer, model, record) {
|
|
|
48
52
|
let field = config.fields[key];
|
|
49
53
|
if (field && field.type === 'mediamanager') {
|
|
50
54
|
const option = field.options;
|
|
51
|
-
let mediaManager =
|
|
55
|
+
let mediaManager = adminizer.mediaManagerHandler.get(option?.id ?? 'default');
|
|
52
56
|
let emptyData = [];
|
|
53
|
-
await mediaManager.setRelations(emptyData, model, record[0].id, key);
|
|
57
|
+
await mediaManager.setRelations(emptyData, model, +record[0].id, key);
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DefaultMediaManager } from "../lib/media-manager/DefaultMediaManager";
|
|
2
|
-
import { MediaManagerHandler } from "../lib/media-manager/MediaManagerHandler";
|
|
3
2
|
import serveStatic from "serve-static";
|
|
4
3
|
import path from "path";
|
|
5
4
|
export default function bindMediaManager(adminizer) {
|
|
@@ -8,7 +7,7 @@ export default function bindMediaManager(adminizer) {
|
|
|
8
7
|
adminizer.emitter.on("adminizer:loaded", async () => {
|
|
9
8
|
try {
|
|
10
9
|
let mediaManager = new DefaultMediaManager(adminizer, 'default', 'media-manager', adminizer.config.mediamanager.fileStoragePath);
|
|
11
|
-
|
|
10
|
+
adminizer.mediaManagerHandler.add(mediaManager);
|
|
12
11
|
}
|
|
13
12
|
catch (e) {
|
|
14
13
|
console.log(e);
|