@geekron/hono 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -0
- package/dist/contract.d.ts +5 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +4 -0
- package/dist/route/index.d.ts +5 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.js +4 -0
- package/dist/route/interfaces.d.ts +35 -0
- package/dist/route/interfaces.d.ts.map +1 -0
- package/dist/route/interfaces.js +1 -0
- package/dist/route/methods.d.ts +13 -0
- package/dist/route/methods.d.ts.map +1 -0
- package/dist/route/methods.js +79 -0
- package/dist/route/setup.d.ts +18 -0
- package/dist/route/setup.d.ts.map +1 -0
- package/dist/route/setup.js +11 -0
- package/dist/route/slot.d.ts +15 -0
- package/dist/route/slot.d.ts.map +1 -0
- package/dist/route/slot.js +28 -0
- package/dist/strapi/cms/cms.d.ts +17 -0
- package/dist/strapi/cms/cms.d.ts.map +1 -0
- package/dist/strapi/cms/cms.js +57 -0
- package/dist/strapi/cms/common.d.ts +9 -0
- package/dist/strapi/cms/common.d.ts.map +1 -0
- package/dist/strapi/cms/common.js +30 -0
- package/dist/strapi/cms/components.d.ts +20 -0
- package/dist/strapi/cms/components.d.ts.map +1 -0
- package/dist/strapi/cms/components.js +33 -0
- package/dist/strapi/cms/content-types.d.ts +48 -0
- package/dist/strapi/cms/content-types.d.ts.map +1 -0
- package/dist/strapi/cms/content-types.js +49 -0
- package/dist/strapi/cms/index.d.ts +10 -0
- package/dist/strapi/cms/index.d.ts.map +1 -0
- package/dist/strapi/cms/index.js +9 -0
- package/dist/strapi/cms/locales.d.ts +16 -0
- package/dist/strapi/cms/locales.d.ts.map +1 -0
- package/dist/strapi/cms/locales.js +33 -0
- package/dist/strapi/cms/menu.d.ts +19 -0
- package/dist/strapi/cms/menu.d.ts.map +1 -0
- package/dist/strapi/cms/menu.js +80 -0
- package/dist/strapi/cms/setup.d.ts +11 -0
- package/dist/strapi/cms/setup.d.ts.map +1 -0
- package/dist/strapi/cms/setup.js +25 -0
- package/dist/strapi/cms/site.d.ts +9 -0
- package/dist/strapi/cms/site.d.ts.map +1 -0
- package/dist/strapi/cms/site.js +30 -0
- package/dist/strapi/cms/translations.d.ts +25 -0
- package/dist/strapi/cms/translations.d.ts.map +1 -0
- package/dist/strapi/cms/translations.js +38 -0
- package/dist/strapi/index.d.ts +5 -0
- package/dist/strapi/index.d.ts.map +1 -0
- package/dist/strapi/index.js +4 -0
- package/dist/strapi/interfaces/index.d.ts +2 -0
- package/dist/strapi/interfaces/index.d.ts.map +1 -0
- package/dist/strapi/interfaces/index.js +1 -0
- package/dist/strapi/interfaces/media.d.ts +42 -0
- package/dist/strapi/interfaces/media.d.ts.map +1 -0
- package/dist/strapi/interfaces/media.js +1 -0
- package/dist/strapi/route.d.ts +3 -0
- package/dist/strapi/route.d.ts.map +1 -0
- package/dist/strapi/route.js +61 -0
- package/dist/strapi/utils/fileTitle.d.ts +3 -0
- package/dist/strapi/utils/fileTitle.d.ts.map +1 -0
- package/dist/strapi/utils/fileTitle.js +3 -0
- package/dist/strapi/utils/fileUrl.d.ts +3 -0
- package/dist/strapi/utils/fileUrl.d.ts.map +1 -0
- package/dist/strapi/utils/fileUrl.js +4 -0
- package/dist/strapi/utils/imgAlt.d.ts +3 -0
- package/dist/strapi/utils/imgAlt.d.ts.map +1 -0
- package/dist/strapi/utils/imgAlt.js +3 -0
- package/dist/strapi/utils/imgInfo.d.ts +9 -0
- package/dist/strapi/utils/imgInfo.d.ts.map +1 -0
- package/dist/strapi/utils/imgInfo.js +13 -0
- package/dist/strapi/utils/imgSrc.d.ts +8 -0
- package/dist/strapi/utils/imgSrc.d.ts.map +1 -0
- package/dist/strapi/utils/imgSrc.js +17 -0
- package/dist/strapi/utils/index.d.ts +7 -0
- package/dist/strapi/utils/index.d.ts.map +1 -0
- package/dist/strapi/utils/index.js +6 -0
- package/dist/strapi/utils/resource.d.ts +7 -0
- package/dist/strapi/utils/resource.d.ts.map +1 -0
- package/dist/strapi/utils/resource.js +17 -0
- package/package.json +42 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../src/strapi/cms/content-types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,eAAe,EAAE,OAAO,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QACtC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAC3C,CAAA;IACD,IAAI,EAAE,gBAAgB,GAAG,YAAY,CAAA;IACrC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAClC,CAAA;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,mBAAmB,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,iBAAiB,CAAA;CACzB;AAOD;;GAEG;AACH,eAAO,MAAM,eAAe,gCAK3B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,4BAEzC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAU,iBAAe,sCAEtD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAU,iBAAc,sCAgBpD,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { cms } from './cms';
|
|
2
|
+
/**
|
|
3
|
+
* 内容类型集合
|
|
4
|
+
*/
|
|
5
|
+
const contentTypes = new Map();
|
|
6
|
+
/**
|
|
7
|
+
* 获取内容类型集合
|
|
8
|
+
*/
|
|
9
|
+
export const getContentTypes = () => {
|
|
10
|
+
if (contentTypes.size === 0) {
|
|
11
|
+
throw new Error('No content types found');
|
|
12
|
+
}
|
|
13
|
+
return contentTypes;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 获取内容类型
|
|
17
|
+
* @param uid
|
|
18
|
+
*/
|
|
19
|
+
export const getContentType = (uid) => {
|
|
20
|
+
return contentTypes.get(uid);
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 获取内容类型
|
|
24
|
+
*/
|
|
25
|
+
export const fetchContentTypes = async (refresh = false) => {
|
|
26
|
+
return await initContentTypes(refresh);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 初始化内容类型
|
|
30
|
+
*/
|
|
31
|
+
export const initContentTypes = async (refresh = true) => {
|
|
32
|
+
try {
|
|
33
|
+
if (refresh)
|
|
34
|
+
contentTypes.clear();
|
|
35
|
+
if (contentTypes.size > 0) {
|
|
36
|
+
return Promise.resolve(contentTypes);
|
|
37
|
+
}
|
|
38
|
+
const res = await cms.fetch('/content-type-builder/content-types');
|
|
39
|
+
const { data } = await res.json();
|
|
40
|
+
data?.forEach((item) => {
|
|
41
|
+
contentTypes.set(item.uid, item);
|
|
42
|
+
});
|
|
43
|
+
return contentTypes;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('contentTypes error', error);
|
|
47
|
+
return new Map();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './cms';
|
|
2
|
+
export * from './common';
|
|
3
|
+
export * from './components';
|
|
4
|
+
export * from './content-types';
|
|
5
|
+
export * from './locales';
|
|
6
|
+
export * from './menu';
|
|
7
|
+
export * from './setup';
|
|
8
|
+
export * from './site';
|
|
9
|
+
export * from './translations';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strapi/cms/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Locale {
|
|
2
|
+
id: number;
|
|
3
|
+
documentId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
code: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
updatedAt: string;
|
|
8
|
+
publishedAt: string;
|
|
9
|
+
isDefault: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const locales: Map<string, Locale>;
|
|
12
|
+
export declare const getLocale: (code: string) => Locale | undefined;
|
|
13
|
+
export declare const getLocales: () => Map<string, Locale>;
|
|
14
|
+
export declare const fetchLocales: (refresh?: boolean) => Promise<Map<string, Locale>>;
|
|
15
|
+
export declare const initLocales: (refresh?: boolean) => Promise<Map<string, Locale>>;
|
|
16
|
+
//# sourceMappingURL=locales.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/strapi/cms/locales.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;CAClB;AAED,eAAO,MAAM,OAAO,qBAA4B,CAAA;AAEhD,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,uBAErC,CAAA;AAED,eAAO,MAAM,UAAU,2BAKtB,CAAA;AAED,eAAO,MAAM,YAAY,GAAU,iBAAe,iCAEjD,CAAA;AAED,eAAO,MAAM,WAAW,GAAU,iBAAc,iCAgB/C,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cms } from './cms';
|
|
2
|
+
export const locales = new Map();
|
|
3
|
+
export const getLocale = (code) => {
|
|
4
|
+
return locales.get(code);
|
|
5
|
+
};
|
|
6
|
+
export const getLocales = () => {
|
|
7
|
+
if (locales.size === 0) {
|
|
8
|
+
throw new Error('locales not found');
|
|
9
|
+
}
|
|
10
|
+
return locales;
|
|
11
|
+
};
|
|
12
|
+
export const fetchLocales = async (refresh = false) => {
|
|
13
|
+
return await initLocales(refresh);
|
|
14
|
+
};
|
|
15
|
+
export const initLocales = async (refresh = true) => {
|
|
16
|
+
try {
|
|
17
|
+
if (refresh)
|
|
18
|
+
locales.clear();
|
|
19
|
+
if (locales.size > 0) {
|
|
20
|
+
return Promise.resolve(locales);
|
|
21
|
+
}
|
|
22
|
+
const res = await cms.fetch('/i18n/locales');
|
|
23
|
+
const items = (await res.json());
|
|
24
|
+
items?.forEach((item) => {
|
|
25
|
+
locales.set(item.code, item);
|
|
26
|
+
});
|
|
27
|
+
return locales;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error('locales error', error);
|
|
31
|
+
return new Map();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface Menu {
|
|
2
|
+
items: any[];
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 获取菜单项
|
|
7
|
+
*/
|
|
8
|
+
export declare const getMenuItems: () => Promise<any[] | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* 获取菜单项
|
|
11
|
+
* @param refresh
|
|
12
|
+
*/
|
|
13
|
+
export declare const fetchMenuItems: (refresh?: boolean) => Promise<any[]>;
|
|
14
|
+
/**
|
|
15
|
+
* 初始化菜单项
|
|
16
|
+
* @param refresh
|
|
17
|
+
*/
|
|
18
|
+
export declare const initMenuItems: (refresh?: boolean) => Promise<any[]>;
|
|
19
|
+
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/strapi/cms/menu.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,IAAI;IACpB,KAAK,EAAE,GAAG,EAAE,CAAA;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAClB;AAmCD;;GAEG;AACH,eAAO,MAAM,YAAY,kCAKxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAU,iBAAe,mBAEnD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,iBAAc,mBA+BjD,CAAA"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { cms } from './cms';
|
|
2
|
+
import { getComponents, getContentTypes, } from './index';
|
|
3
|
+
const makePopulate = async (type, option) => {
|
|
4
|
+
const component = option.components.get(`menu.${type}`);
|
|
5
|
+
const attributes = Object.keys(component?.schema?.attributes || {}).filter((key) => key !== 'type');
|
|
6
|
+
return attributes.reduce((res, key) => {
|
|
7
|
+
const uid = component?.schema?.attributes[key].target;
|
|
8
|
+
const contentType = option.types.get(uid);
|
|
9
|
+
if (contentType?.schema.attributes.menuImage) {
|
|
10
|
+
res.push(`items.${type}.${key}.menuImage`);
|
|
11
|
+
res.push(`items.children.${type}.${key}.menuImage`);
|
|
12
|
+
res.push(`items.children.children.${type}.${key}.menuImage`);
|
|
13
|
+
}
|
|
14
|
+
else if (contentType?.schema.attributes.image) {
|
|
15
|
+
res.push(`items.${type}.${key}.image`);
|
|
16
|
+
res.push(`items.children.${type}.${key}.image`);
|
|
17
|
+
res.push(`items.children.children.${type}.${key}.image`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
res.push(`items.${type}.${key}`);
|
|
21
|
+
res.push(`items.children.${type}.${key}`);
|
|
22
|
+
res.push(`items.children.children.${type}.${key}`);
|
|
23
|
+
}
|
|
24
|
+
return res;
|
|
25
|
+
}, []);
|
|
26
|
+
};
|
|
27
|
+
const menu = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* 获取菜单项
|
|
30
|
+
*/
|
|
31
|
+
export const getMenuItems = async () => {
|
|
32
|
+
if (menu.size === 0) {
|
|
33
|
+
throw new Error('menus not found');
|
|
34
|
+
}
|
|
35
|
+
return menu.get('items');
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* 获取菜单项
|
|
39
|
+
* @param refresh
|
|
40
|
+
*/
|
|
41
|
+
export const fetchMenuItems = async (refresh = false) => {
|
|
42
|
+
return await initMenuItems(refresh);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 初始化菜单项
|
|
46
|
+
* @param refresh
|
|
47
|
+
*/
|
|
48
|
+
export const initMenuItems = async (refresh = true) => {
|
|
49
|
+
if (refresh)
|
|
50
|
+
menu.clear();
|
|
51
|
+
if (menu.size > 0) {
|
|
52
|
+
return menu.get('items') || [];
|
|
53
|
+
}
|
|
54
|
+
const components = getComponents();
|
|
55
|
+
const types = getContentTypes();
|
|
56
|
+
const [pagesPopulate, itemsPopulate] = await Promise.all([
|
|
57
|
+
makePopulate('page', {
|
|
58
|
+
components,
|
|
59
|
+
types,
|
|
60
|
+
}),
|
|
61
|
+
makePopulate('items', {
|
|
62
|
+
components,
|
|
63
|
+
types,
|
|
64
|
+
}),
|
|
65
|
+
]);
|
|
66
|
+
const { items } = await cms
|
|
67
|
+
.single('menu')
|
|
68
|
+
.find({
|
|
69
|
+
populate: [
|
|
70
|
+
...pagesPopulate,
|
|
71
|
+
...itemsPopulate,
|
|
72
|
+
'items.image',
|
|
73
|
+
'items.children.image',
|
|
74
|
+
'items.children.children.image',
|
|
75
|
+
],
|
|
76
|
+
})
|
|
77
|
+
.then((res) => (res.data || {}));
|
|
78
|
+
menu.set('items', items || []);
|
|
79
|
+
return items || [];
|
|
80
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CommonPopulate, type SitePopulate } from './index';
|
|
2
|
+
export interface StrapiOption {
|
|
3
|
+
commonPopulate?: CommonPopulate;
|
|
4
|
+
sitePopulate?: SitePopulate;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 初始化strapi
|
|
8
|
+
*/
|
|
9
|
+
export declare const setupStrapi: (option?: StrapiOption) => Promise<void>;
|
|
10
|
+
export declare const resetStrapi: () => Promise<void>;
|
|
11
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/strapi/cms/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,cAAc,EASnB,KAAK,YAAY,EACjB,MAAM,SAAS,CAAA;AAMhB,MAAM,WAAW,YAAY;IAC5B,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,YAAY,CAAC,EAAE,YAAY,CAAA;CAC3B;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,SAAS,YAAY,kBAYtD,CAAA;AAED,eAAO,MAAM,WAAW,qBAIvB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { checkCmsStatus, initCommon, initComponents, initContentTypes, initLocales, initMenuItems, initSite, initTranslations, } from './index';
|
|
2
|
+
const strapi = {
|
|
3
|
+
status: false,
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* 初始化strapi
|
|
7
|
+
*/
|
|
8
|
+
export const setupStrapi = async (option) => {
|
|
9
|
+
await checkCmsStatus();
|
|
10
|
+
await Promise.all([
|
|
11
|
+
initContentTypes(),
|
|
12
|
+
initComponents(),
|
|
13
|
+
initLocales(),
|
|
14
|
+
initTranslations(),
|
|
15
|
+
initSite(option?.sitePopulate || '*'),
|
|
16
|
+
initCommon(option?.commonPopulate || '*'),
|
|
17
|
+
]);
|
|
18
|
+
await initMenuItems();
|
|
19
|
+
strapi.status = true;
|
|
20
|
+
};
|
|
21
|
+
export const resetStrapi = async () => {
|
|
22
|
+
if (strapi.status) {
|
|
23
|
+
await setupStrapi();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Site {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
export type SitePopulate = string | string[] | Record<string, unknown>;
|
|
5
|
+
export declare const setSite: (site: Site) => void;
|
|
6
|
+
export declare const getSite: <T = Site>() => T;
|
|
7
|
+
export declare const fetchSite: (populate?: SitePopulate, refresh?: boolean) => Promise<Site>;
|
|
8
|
+
export declare const initSite: (populate?: SitePopulate, refresh?: boolean) => Promise<Site>;
|
|
9
|
+
//# sourceMappingURL=site.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../../../src/strapi/cms/site.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,IAAI;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAClB;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAGtE,eAAO,MAAM,OAAO,GAAI,MAAM,IAAI,SAEjC,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,CAAC,GAAG,IAAI,OAKhB,CACf,CAAA;AAED,eAAO,MAAM,SAAS,GAAU,WAAU,YAAkB,EAAE,iBAAe,kBAE5E,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,WAAU,YAAkB,EAAE,iBAAc,kBAa1E,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cms } from './cms';
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
export const setSite = (site) => {
|
|
4
|
+
cache.set('site', site);
|
|
5
|
+
};
|
|
6
|
+
export const getSite = () => {
|
|
7
|
+
const site = cache.get('site');
|
|
8
|
+
if (!site) {
|
|
9
|
+
throw new Error('site not found');
|
|
10
|
+
}
|
|
11
|
+
return site;
|
|
12
|
+
};
|
|
13
|
+
export const fetchSite = async (populate = '*', refresh = false) => {
|
|
14
|
+
return await initSite(populate, refresh);
|
|
15
|
+
};
|
|
16
|
+
export const initSite = async (populate = '*', refresh = true) => {
|
|
17
|
+
if (refresh)
|
|
18
|
+
cache.clear();
|
|
19
|
+
if (cache.has('site')) {
|
|
20
|
+
return Promise.resolve(cache.get('site'));
|
|
21
|
+
}
|
|
22
|
+
const site = await cms
|
|
23
|
+
.single('site')
|
|
24
|
+
.find({
|
|
25
|
+
populate,
|
|
26
|
+
})
|
|
27
|
+
.then((res) => res.data);
|
|
28
|
+
setSite(site);
|
|
29
|
+
return getSite();
|
|
30
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface Translation {
|
|
2
|
+
id: number;
|
|
3
|
+
documentId: string;
|
|
4
|
+
key: string;
|
|
5
|
+
value: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
updatedAt: string;
|
|
8
|
+
publishedAt: string;
|
|
9
|
+
locale: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 获取翻译
|
|
13
|
+
*/
|
|
14
|
+
export declare const getTranslations: () => Translation[];
|
|
15
|
+
/**
|
|
16
|
+
* 获取翻译
|
|
17
|
+
* @param refresh
|
|
18
|
+
*/
|
|
19
|
+
export declare const fetchTranslations: (refresh?: boolean) => Promise<Translation[]>;
|
|
20
|
+
/**
|
|
21
|
+
* 初始化翻译
|
|
22
|
+
* @param refresh
|
|
23
|
+
*/
|
|
24
|
+
export declare const initTranslations: (refresh?: boolean) => Promise<Translation[]>;
|
|
25
|
+
//# sourceMappingURL=translations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../../src/strapi/cms/translations.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACd;AAID;;GAEG;AACH,eAAO,MAAM,eAAe,qBAE3B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAU,iBAAe,2BAEtD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAU,iBAAc,2BAgBpD,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { cms } from './cms';
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
/**
|
|
4
|
+
* 获取翻译
|
|
5
|
+
*/
|
|
6
|
+
export const getTranslations = () => {
|
|
7
|
+
return cache.get('translations') || [];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 获取翻译
|
|
11
|
+
* @param refresh
|
|
12
|
+
*/
|
|
13
|
+
export const fetchTranslations = async (refresh = false) => {
|
|
14
|
+
return await initTranslations(refresh);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 初始化翻译
|
|
18
|
+
* @param refresh
|
|
19
|
+
*/
|
|
20
|
+
export const initTranslations = async (refresh = true) => {
|
|
21
|
+
try {
|
|
22
|
+
if (refresh)
|
|
23
|
+
cache.clear();
|
|
24
|
+
if (cache.has('translations')) {
|
|
25
|
+
return Promise.resolve(cache.get('translations') || []);
|
|
26
|
+
}
|
|
27
|
+
const translations = await cms
|
|
28
|
+
.collection('translations')
|
|
29
|
+
.find()
|
|
30
|
+
.then((res) => res.data || []);
|
|
31
|
+
cache.set('translations', translations);
|
|
32
|
+
return translations;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error('translations error', error);
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/strapi/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strapi/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './media';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface MediaImageFormat {
|
|
2
|
+
name: string;
|
|
3
|
+
hash: string;
|
|
4
|
+
ext: string;
|
|
5
|
+
mime: string;
|
|
6
|
+
path: string | null;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
size: number;
|
|
10
|
+
sizeInBytes: number;
|
|
11
|
+
url: string;
|
|
12
|
+
}
|
|
13
|
+
export interface MediaImage extends MediaFile {
|
|
14
|
+
formats: {
|
|
15
|
+
thumbnail?: MediaImageFormat;
|
|
16
|
+
small?: MediaImageFormat;
|
|
17
|
+
medium?: MediaImageFormat;
|
|
18
|
+
large?: MediaImageFormat;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface MediaFile {
|
|
22
|
+
id: number;
|
|
23
|
+
documentId: string;
|
|
24
|
+
name: string;
|
|
25
|
+
alternativeText: string;
|
|
26
|
+
caption: string;
|
|
27
|
+
width: null | number;
|
|
28
|
+
height: null | number;
|
|
29
|
+
formats: null | object;
|
|
30
|
+
hash: string;
|
|
31
|
+
ext: string;
|
|
32
|
+
mime: string;
|
|
33
|
+
size: number;
|
|
34
|
+
url: string;
|
|
35
|
+
previewUrl: null | string;
|
|
36
|
+
provider: string;
|
|
37
|
+
provider_metadata: null | object;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
publishedAt: string;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../src/strapi/interfaces/media.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC5C,OAAO,EAAE;QACR,SAAS,CAAC,EAAE,gBAAgB,CAAA;QAC5B,KAAK,CAAC,EAAE,gBAAgB,CAAA;QACxB,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,KAAK,CAAC,EAAE,gBAAgB,CAAA;KACxB,CAAA;CACD;AAED,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,IAAI,GAAG,MAAM,CAAA;IACpB,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,OAAO,EAAE,IAAI,GAAG,MAAM,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,IAAI,GAAG,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB,EAAE,IAAI,GAAG,MAAM,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/strapi/route.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,eAAO,MAAM,gBAAgB,EAAE,gBAuC9B,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { kebabCase, trim } from 'voca';
|
|
2
|
+
import { URL_SUFFIX } from '../contract';
|
|
3
|
+
export const routeItemHandler = (method) => {
|
|
4
|
+
return (path, option) => {
|
|
5
|
+
const name = option?.name || kebabCase(path);
|
|
6
|
+
if (option.suffix === undefined) {
|
|
7
|
+
option.suffix = trim(URL_SUFFIX, '.');
|
|
8
|
+
}
|
|
9
|
+
const pathSeparated = path.split('.');
|
|
10
|
+
if (pathSeparated.length > 1) {
|
|
11
|
+
option.suffix = pathSeparated.pop();
|
|
12
|
+
}
|
|
13
|
+
if (path === '/') {
|
|
14
|
+
option.suffix = '';
|
|
15
|
+
}
|
|
16
|
+
// 创建 fullPath
|
|
17
|
+
const fullPath = makeFullPath(path, option.suffix || '');
|
|
18
|
+
// 获取参数
|
|
19
|
+
const params = path
|
|
20
|
+
.split('/')
|
|
21
|
+
.filter((part) => part.startsWith(':'))
|
|
22
|
+
.map((param) => {
|
|
23
|
+
return trim(param.split('.')[0], ':');
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
method,
|
|
27
|
+
path,
|
|
28
|
+
fullPath,
|
|
29
|
+
name,
|
|
30
|
+
params,
|
|
31
|
+
suffix: option.suffix || '',
|
|
32
|
+
dataType: option.dataType,
|
|
33
|
+
sitemap: option.sitemap,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
function makeFullPath(path, suffix) {
|
|
38
|
+
if (path === '/') {
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
const pathSeparated = path.split('.');
|
|
42
|
+
if (pathSeparated.length > 1) {
|
|
43
|
+
pathSeparated.pop();
|
|
44
|
+
}
|
|
45
|
+
path = pathSeparated.join('.');
|
|
46
|
+
if (!suffix)
|
|
47
|
+
return path;
|
|
48
|
+
// 按 '/' 分割路径
|
|
49
|
+
const parts = path.split('/').filter(Boolean); // 过滤掉空字符串(如开头的 /)
|
|
50
|
+
const lastPart = parts[parts.length - 1];
|
|
51
|
+
// 判断最后一段是否是动态参数(以 : 开头)
|
|
52
|
+
if (lastPart.startsWith(':')) {
|
|
53
|
+
// 动态段:替换为 :param{.+\.suffix}
|
|
54
|
+
parts[parts.length - 1] = `${lastPart}{.+\\.${suffix}}`;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// 静态段:直接加后缀
|
|
58
|
+
parts[parts.length - 1] = `${lastPart}.${suffix}`;
|
|
59
|
+
}
|
|
60
|
+
return `/${parts.join('/')}`;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileTitle.d.ts","sourceRoot":"","sources":["../../../src/strapi/utils/fileTitle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,SAAS,GAAI,MAAM,SAAS,WAExC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileUrl.d.ts","sourceRoot":"","sources":["../../../src/strapi/utils/fileUrl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,OAAO,GAAI,MAAM,SAAS,WAEtC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imgAlt.d.ts","sourceRoot":"","sources":["../../../src/strapi/utils/imgAlt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,eAAO,MAAM,MAAM,GAAI,OAAO,UAAU,WAEvC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imgInfo.d.ts","sourceRoot":"","sources":["../../../src/strapi/utils/imgInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAI/C,eAAO,MAAM,OAAO,GAAI,OAAO,UAAU;;;;;;aASxC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { imgAlt } from './imgAlt';
|
|
2
|
+
import { imgSrc } from './imgSrc';
|
|
3
|
+
export const imgInfo = (image) => {
|
|
4
|
+
if (!image)
|
|
5
|
+
return undefined;
|
|
6
|
+
return {
|
|
7
|
+
alt: imgAlt(image),
|
|
8
|
+
src: imgSrc(image),
|
|
9
|
+
width: image.width || 0,
|
|
10
|
+
height: image.height || 0,
|
|
11
|
+
caption: image?.caption || image?.name,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MediaImage } from '../interfaces';
|
|
2
|
+
export declare const imgSrc: (image: MediaImage, format?: keyof MediaImage["formats"] | null, options?: {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
format?: "webp" | "jpg" | "png";
|
|
6
|
+
quality?: number;
|
|
7
|
+
}) => string;
|
|
8
|
+
//# sourceMappingURL=imgSrc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imgSrc.d.ts","sourceRoot":"","sources":["../../../src/strapi/utils/imgSrc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,eAAO,MAAM,MAAM,GAClB,OAAO,UAAU,EACjB,SAAS,MAAM,UAAU,CAAC,SAAS,CAAC,GAAG,IAAI,EAC3C,UAAU;IACT,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAAA;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB,WAgBD,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MEDIA_URL } from '../../contract';
|
|
2
|
+
export const imgSrc = (image, format, options) => {
|
|
3
|
+
const src = format ? image?.formats?.[format || 'thumbnail']?.url : image?.url;
|
|
4
|
+
const params = new URLSearchParams();
|
|
5
|
+
// 添加图片优化参数
|
|
6
|
+
if (options?.width)
|
|
7
|
+
params.append('width', String(options.width));
|
|
8
|
+
if (options?.height)
|
|
9
|
+
params.append('height', String(options.width));
|
|
10
|
+
if (options?.format)
|
|
11
|
+
params.append('format', options.format);
|
|
12
|
+
if (options?.quality)
|
|
13
|
+
params.append('quality', String(options.quality));
|
|
14
|
+
const baseUrl = `${MEDIA_URL}${src}`;
|
|
15
|
+
const queryString = params.toString();
|
|
16
|
+
return queryString ? `${baseUrl}?${queryString}` : baseUrl;
|
|
17
|
+
};
|