@rxdrag/website-lib-core 0.0.68 → 0.0.69

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdrag/website-lib-core",
3
- "version": "0.0.68",
3
+ "version": "0.0.69",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts"
@@ -35,8 +35,8 @@
35
35
  "lodash-es": "^4.17.21",
36
36
  "react": "^19.1.0",
37
37
  "react-dom": "^19.1.0",
38
- "@rxdrag/entify-lib": "0.0.19",
39
- "@rxdrag/rxcms-models": "0.3.90"
38
+ "@rxdrag/entify-lib": "0.0.20",
39
+ "@rxdrag/rxcms-models": "0.3.91"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "astro": "^4.0.0 || ^5.0.0"
@@ -32,6 +32,26 @@ export const DEFAULT_LARGE: ImageResize = {
32
32
  height: 1200,
33
33
  };
34
34
 
35
+ export const DEFAULT_PRODUCT_IMAGE_SIZE: ImageResize = {
36
+ width: 800,
37
+ height: 800,
38
+ };
39
+
40
+ export const DEFAULT_PRODUCT_THUMBNAIL_IMAGE_SIZE: ImageResize = {
41
+ width: 600,
42
+ height: 400,
43
+ };
44
+
45
+ export const DEFAULT_POST_IMAGE_SIZE: ImageResize = {
46
+ width: 800,
47
+ height: 600,
48
+ };
49
+
50
+ export const DEFAULT_POST_THUMBNAIL_IMAGE_SIZE: ImageResize = {
51
+ width: 600,
52
+ height: 400,
53
+ };
54
+
35
55
  //TODO:以后还要加transform参数
36
56
  export type ImageProps = ImgHTMLAttributes<HTMLImageElement> & {
37
57
  className?: string;
@@ -52,29 +72,25 @@ export const transformMeidaFields = (
52
72
  const fields = ["original", "thumbnail"];
53
73
  if (resize) {
54
74
  fields.push(
55
- `resize(width: ${resize.width || DEFUALT_WIDTH}, height: ${
56
- resize.height || DEFUALT_HEIGHT
75
+ `resize(width: ${resize.width || DEFUALT_WIDTH}, height: ${resize.height || DEFUALT_HEIGHT
57
76
  })`
58
77
  );
59
78
  }
60
79
  if (field === "small") {
61
80
  fields.push(
62
- `small(width: ${images?.small?.width || DEFAULT_SAMLL.width}, height: ${
63
- images?.small?.height || DEFAULT_SAMLL.height
81
+ `small(width: ${images?.small?.width || DEFAULT_SAMLL.width}, height: ${images?.small?.height || DEFAULT_SAMLL.height
64
82
  })`
65
83
  );
66
84
  }
67
85
  if (field === "medium") {
68
86
  fields.push(
69
- `medium(width: ${
70
- images?.medium?.width || DEFAULT_MEDIUM.width
87
+ `medium(width: ${images?.medium?.width || DEFAULT_MEDIUM.width
71
88
  }, height: ${images?.medium?.height || DEFAULT_MEDIUM.height})`
72
89
  );
73
90
  }
74
91
  if (field === "large") {
75
92
  fields.push(
76
- `large(width: ${images?.large?.width || DEFAULT_LARGE.width}, height: ${
77
- images?.large?.height || DEFAULT_LARGE.height
93
+ `large(width: ${images?.large?.width || DEFAULT_LARGE.width}, height: ${images?.large?.height || DEFAULT_LARGE.height
78
94
  })`
79
95
  );
80
96
  }
@@ -1,4 +1,4 @@
1
- import { EnvVariables, TSize } from "./types";
1
+ import { EnvVariables } from "./types";
2
2
  import { queryOneTheme } from "./lib/queryOneTheme";
3
3
  import {
4
4
  ListConditions,
@@ -29,6 +29,7 @@ import { queryUserIds } from "./lib/queryUserIds";
29
29
  import { IEntify, PostPatinateOptions, PostsOptions } from "./IEntify";
30
30
  import { queryWebsite } from "./lib/queryWebsite";
31
31
  import {
32
+ ImageSize,
32
33
  ImageSizes,
33
34
  Media,
34
35
  Page,
@@ -44,22 +45,20 @@ import { queryOneMedia } from "./lib/queryOneMedia";
44
45
  export class Entify implements IEntify {
45
46
  private static instance: Entify | null = null;
46
47
 
47
- private constructor(protected envVariables: EnvVariables) { }
48
+ private constructor(protected envVariables: EnvVariables, protected imageSizes: ImageSizes) { }
48
49
 
49
- public static getInstance(envVariables: EnvVariables): Entify {
50
+ public static getInstance(envVariables: EnvVariables, imageSizes: ImageSizes): Entify {
50
51
  if (!Entify.instance) {
51
- Entify.instance = new Entify(envVariables);
52
+ Entify.instance = new Entify(envVariables, imageSizes);
52
53
  }
53
54
  return Entify.instance;
54
55
  }
55
56
 
56
- private imageSizes: ImageSizes | undefined;
57
-
58
- public setImageSizes(imageSizes: ImageSizes | undefined): void {
57
+ public setImageSizes(imageSizes: ImageSizes): void {
59
58
  this.imageSizes = imageSizes;
60
59
  }
61
60
 
62
- public getImageSizes(): ImageSizes | undefined {
61
+ public getImageSizes(): ImageSizes {
63
62
  return this.imageSizes;
64
63
  }
65
64
 
@@ -106,9 +105,12 @@ export class Entify implements IEntify {
106
105
 
107
106
  public async getFeaturedProducts(
108
107
  count?: number,
109
- imageSize?: TSize,
108
+ imageSize?: ImageSize,
110
109
  addonFields?: (keyof Product)[]
111
110
  ) {
111
+ if (!imageSize) {
112
+ imageSize = this.imageSizes.productThumbnial;
113
+ }
112
114
  return await queryFeaturedProducts(
113
115
  count,
114
116
  imageSize,
@@ -117,7 +119,10 @@ export class Entify implements IEntify {
117
119
  );
118
120
  }
119
121
 
120
- public async getLatestPosts(count?: number, coverSize?: TSize) {
122
+ public async getLatestPosts(count?: number, coverSize?: ImageSize) {
123
+ if (!coverSize) {
124
+ coverSize = this.imageSizes.postThumbnial;
125
+ }
121
126
  return await queryLatestPosts(count, coverSize, this.envVariables);
122
127
  }
123
128
 
@@ -198,7 +203,10 @@ export class Entify implements IEntify {
198
203
  }));
199
204
  }
200
205
 
201
- public async getPostBySlug(slug: string, coverSize: TSize | undefined) {
206
+ public async getPostBySlug(slug: string, coverSize: ImageSize | undefined) {
207
+ if (!coverSize) {
208
+ coverSize = this.imageSizes.post;
209
+ }
202
210
  return await queryOnePostBySlug(slug, coverSize, this.envVariables);
203
211
  }
204
212
 
@@ -223,9 +231,12 @@ export class Entify implements IEntify {
223
231
 
224
232
  public async getProducts(
225
233
  conditions: ListConditions,
226
- imageSize: TSize | undefined,
234
+ imageSize: ImageSize | undefined,
227
235
  addonFields?: (keyof Product)[]
228
236
  ) {
237
+ if (!imageSize) {
238
+ imageSize = this.imageSizes.productThumbnial;
239
+ }
229
240
  return (
230
241
  await queryProducts(conditions, imageSize, this.envVariables, addonFields)
231
242
  )?.items;
@@ -372,7 +383,10 @@ export class Entify implements IEntify {
372
383
  return paths;
373
384
  }
374
385
 
375
- public async getProductBySlug(slug: string, imageSize: TSize | undefined) {
386
+ public async getProductBySlug(slug: string, imageSize: ImageSize | undefined) {
387
+ if (!imageSize) {
388
+ imageSize = this.imageSizes.product;
389
+ }
376
390
  return await queryOneProductBySlug(slug, imageSize, this.envVariables);
377
391
  }
378
392
 
@@ -418,7 +432,10 @@ export class Entify implements IEntify {
418
432
  return (await queryUserPosts({ userId }, this.envVariables))?.items;
419
433
  }
420
434
 
421
- public async fulltextSearch(keyword: string, imageSize: TSize | undefined) {
435
+ public async fulltextSearch(keyword: string, imageSize: ImageSize | undefined) {
436
+ if (!imageSize) {
437
+ imageSize = this.imageSizes.postThumbnial;
438
+ }
422
439
  return await fulltextSearch(keyword, imageSize, this.envVariables);
423
440
  }
424
441
 
@@ -1,5 +1,4 @@
1
1
  import { IQueryOptions, ListResult } from "@rxdrag/entify-lib";
2
- import { TSize } from "./types";
3
2
  import { ListConditions, UploadOptions, UploadSession } from "./lib";
4
3
  import {
5
4
  TPost,
@@ -9,6 +8,7 @@ import {
9
8
  TUser,
10
9
  } from "./view-model";
11
10
  import {
11
+ ImageSize,
12
12
  ImageSizes,
13
13
  Lang,
14
14
  Media,
@@ -24,7 +24,7 @@ import { WebsitePartBoolExp } from "@rxdrag/rxcms-models/";
24
24
 
25
25
  export type PostsOptions = {
26
26
  category?: string;
27
- coverSize?: TSize | undefined;
27
+ coverSize?: ImageSize | undefined;
28
28
  page: number;
29
29
  pageSize: number;
30
30
  };
@@ -36,8 +36,8 @@ export type PostPatinateOptions = {
36
36
 
37
37
  export interface IEntify {
38
38
  //从配置文件注入到这里面,供组件使用
39
- setImageSizes(imageSizes: ImageSizes | undefined): void;
40
- getImageSizes(): ImageSizes | undefined;
39
+ setImageSizes(imageSizes: ImageSizes): void;
40
+ getImageSizes(): ImageSizes;
41
41
  getLang(): string;
42
42
  queryEntityList<
43
43
  T,
@@ -62,13 +62,13 @@ export interface IEntify {
62
62
 
63
63
  getFeaturedProducts(
64
64
  count?: number,
65
- imageSize?: TSize,
65
+ imageSize?: ImageSize,
66
66
  addonFields?: (keyof Product)[]
67
67
  ): Promise<TProduct[] | undefined>;
68
68
 
69
69
  getLatestPosts(
70
70
  count?: number,
71
- coverSize?: TSize
71
+ coverSize?: ImageSize
72
72
  ): Promise<TPost[] | undefined>;
73
73
 
74
74
  getPosts(options: PostsOptions): Promise<TPost[] | undefined>;
@@ -107,7 +107,7 @@ export interface IEntify {
107
107
 
108
108
  getPostBySlug(
109
109
  slug: string,
110
- coverSize: TSize | undefined
110
+ coverSize: ImageSize | undefined
111
111
  ): Promise<TPost | undefined>;
112
112
 
113
113
  getPostSlugs(): Promise<Array<string | undefined>>;
@@ -118,7 +118,7 @@ export interface IEntify {
118
118
 
119
119
  getProducts(
120
120
  conditions: ListConditions,
121
- imageSize: TSize | undefined,
121
+ imageSize: ImageSize | undefined,
122
122
  addonFields?: (keyof Product)[]
123
123
  ): Promise<TProduct[] | undefined>;
124
124
 
@@ -133,7 +133,7 @@ export interface IEntify {
133
133
 
134
134
  getProductBySlug(
135
135
  slug: string,
136
- imageSize: TSize | undefined
136
+ imageSize: ImageSize | undefined
137
137
  ): Promise<TProduct | undefined>;
138
138
 
139
139
  getProductPaths(): Promise<unknown>;
@@ -152,7 +152,7 @@ export interface IEntify {
152
152
 
153
153
  fulltextSearch(
154
154
  keyword: string,
155
- imageSize: TSize | undefined
155
+ imageSize: ImageSize | undefined
156
156
  ): Promise<ListResult<SearchIndex> | undefined>;
157
157
 
158
158
  getUserPaths(): Promise<unknown>;
@@ -7,14 +7,15 @@ import {
7
7
  SearchIndexQueryOptions,
8
8
  SearchIndexFields,
9
9
  MediaQueryOptions,
10
+ ImageSize,
10
11
  } from "@rxdrag/rxcms-models";
11
12
  import { queryEntityList } from "./queryEntityList";
12
13
  import { ListResult } from "@rxdrag/entify-lib";
13
- import { EnvVariables, TSize } from "../types";
14
+ import { EnvVariables } from "../types";
14
15
 
15
16
  export async function fulltextSearch(
16
17
  keyword: string,
17
- imageSize: TSize | undefined,
18
+ imageSize: ImageSize | undefined,
18
19
  envVariables: EnvVariables
19
20
  ) {
20
21
 
@@ -5,12 +5,13 @@ import {
5
5
  UserFields,
6
6
  MediaQueryOptions,
7
7
  PostCategoryFields,
8
+ ImageSize,
8
9
  } from "@rxdrag/rxcms-models";
9
- import { TSize } from "../types";
10
+
10
11
  import { newPageMetaOptions } from "./newPageMetaOptions";
11
12
 
12
13
  //查询一个产品的参数,不带条件
13
- export function newQueryOnePostOptions(coverSize?: TSize) {
14
+ export function newQueryOnePostOptions(coverSize?: ImageSize) {
14
15
  const coverFields = ["thumbnail", "url"];
15
16
  if (coverSize?.width && coverSize?.height) {
16
17
  coverFields.push(
@@ -9,11 +9,11 @@ import {
9
9
  AttachmentOnProductFields,
10
10
  ProductCategoryFields,
11
11
  ProductRelatedPivotQueryOptions,
12
+ ImageSize,
12
13
  } from "@rxdrag/rxcms-models";
13
- import { TSize } from "../types";
14
14
  import { newPageMetaOptions } from "./newPageMetaOptions";
15
15
 
16
- function creatProductMediaOptions(imagSize?: TSize) {
16
+ function creatProductMediaOptions(imagSize?: ImageSize) {
17
17
  const imageFields = ["thumbnail(width:400, height:320)", "url"];
18
18
  if (imagSize?.width && imagSize?.height) {
19
19
  imageFields.push(
@@ -39,7 +39,7 @@ function creatProductMediaOptions(imagSize?: TSize) {
39
39
  ).media(new MediaQueryOptions().description().file(imageFields));
40
40
  }
41
41
 
42
- export function newQueryProductOptions(imagSize?: TSize) {
42
+ export function newQueryProductOptions(imagSize?: ImageSize) {
43
43
  return new ProductQueryOptions([
44
44
  ProductFields.id,
45
45
  ProductFields.title,
@@ -2,10 +2,10 @@ import {
2
2
  MediaOnProductQueryOptions,
3
3
  MediaOnProductFields,
4
4
  MediaQueryOptions,
5
+ ImageSize,
5
6
  } from "@rxdrag/rxcms-models";
6
- import { TSize } from "../types";
7
7
 
8
- export function newQueryProductsMediaOptions(imageSize?: TSize | undefined) {
8
+ export function newQueryProductsMediaOptions(imageSize?: ImageSize | undefined) {
9
9
  return new MediaOnProductQueryOptions(
10
10
  [MediaOnProductFields.seqValue, MediaOnProductFields.altText],
11
11
  {
@@ -1,8 +1,8 @@
1
1
  import { IQueryOptions, ListResult } from "@rxdrag/entify-lib";
2
2
  import { createEntifyClient } from "./createEntifyClient";
3
3
  import { EnvVariables } from "../types";
4
- import { MediaEntityName, Post, PostCategoryEntityName, PostEntityName, Product, ProductCategoryEntityName, ProductEntityName, UserEntityName } from "@rxdrag/rxcms-models";
5
- import { mediaListToViewModel, postCategoriesToViewModel, postListToViewModel, productCategoriesToViewModel, productListToViewModel, userListToViewModel } from "../view-model";
4
+ import { Post, PostCategoryEntityName, PostEntityName, Product, ProductCategoryEntityName, ProductEntityName, UserEntityName } from "@rxdrag/rxcms-models";
5
+ import { postCategoriesToViewModel, postListToViewModel, productCategoriesToViewModel, productListToViewModel, userListToViewModel } from "../view-model";
6
6
 
7
7
  export async function queryEntityList<T, WhereExp = unknown, OrderBy = unknown, DistinctExp = unknown>(
8
8
  options: IQueryOptions<T, WhereExp, OrderBy, DistinctExp>,
@@ -37,8 +37,6 @@ export async function queryEntityList<T, WhereExp = unknown, OrderBy = unknown,
37
37
  return postCategoriesToViewModel(result as ListResult<Post> | undefined);
38
38
  case UserEntityName:
39
39
  return userListToViewModel(result as ListResult<Post> | undefined);
40
- case MediaEntityName:
41
- return mediaListToViewModel(result as ListResult<Post> | undefined);
42
40
  }
43
41
  return result;
44
42
  }
@@ -5,16 +5,17 @@ import {
5
5
  ProductDistinctExp,
6
6
  ProductFields,
7
7
  ProductQueryOptions,
8
+ ImageSize,
8
9
  } from "@rxdrag/rxcms-models";
9
10
  import { queryEntityList } from "./queryEntityList";
10
11
  import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
11
- import { EnvVariables, TSize } from "../types";
12
+ import { EnvVariables } from "../types";
12
13
  import { ListResult } from "@rxdrag/entify-lib";
13
14
  import { TProduct } from "../view-model";
14
15
 
15
16
  export async function queryFeaturedProducts(
16
17
  count: number = 8,
17
- imageSize: TSize | undefined,
18
+ imageSize: ImageSize | undefined,
18
19
  envVariables: EnvVariables,
19
20
  addonFields?: (keyof Product)[]
20
21
  ) {
@@ -13,12 +13,13 @@ import {
13
13
  PostCategoryFields,
14
14
  } from "@rxdrag/rxcms-models";
15
15
  import { queryEntityList } from "./queryEntityList";
16
- import { EnvVariables, TSize } from "../types";
16
+ import { EnvVariables } from "../types";
17
17
  import { TPost } from "../view-model";
18
+ import { ImageSize } from "@rxdrag/rxcms-models";
18
19
 
19
20
  export async function queryLatestPosts(
20
21
  count: number = 2,
21
- coverSize: TSize | undefined,
22
+ coverSize: ImageSize | undefined,
22
23
  envVariables: EnvVariables
23
24
  ) {
24
25
  const result = await queryEntityList<
@@ -1,7 +1,6 @@
1
1
  import { IQueryOptions } from "@rxdrag/entify-lib";
2
2
  import { createEntifyClient } from "./createEntifyClient";
3
3
  import {
4
- MediaEntityName,
5
4
  PostCategoryEntityName,
6
5
  PostEntityName,
7
6
  ProductCategoryEntityName,
@@ -13,7 +12,6 @@ import {
13
12
  import { WebsitePartBoolExp } from "@rxdrag/rxcms-models/";
14
13
  import { EnvVariables } from "../types";
15
14
  import {
16
- mediaToViewModel,
17
15
  postCategoryToViewModel,
18
16
  postToViewModel,
19
17
  productCategoryToViewModel,
@@ -57,8 +55,6 @@ export async function queryOneEntity<
57
55
  return postCategoryToViewModel(result) as T | undefined;
58
56
  case UserEntityName:
59
57
  return userToViewModel(result) as T | undefined;
60
- case MediaEntityName:
61
- return mediaToViewModel(result) as T | undefined;
62
58
  case WebsiteSettingsEntityName:
63
59
  return websiteSettingsToViewModel(result) as T | undefined;
64
60
  }
@@ -6,12 +6,13 @@ import {
6
6
  } from "@rxdrag/rxcms-models";
7
7
  import { newQueryOnePostOptions } from "./newQueryPostOptions";
8
8
  import { queryOneEntity } from "./queryOneEntity";
9
- import { EnvVariables, TSize } from "../types";
9
+ import { EnvVariables } from "../types";
10
10
  import { TPost } from "../view-model";
11
+ import { ImageSize } from "@rxdrag/rxcms-models";
11
12
 
12
13
  export async function queryOnePostBySlug(
13
14
  slug: string,
14
- coverSize: TSize | undefined,
15
+ coverSize: ImageSize | undefined,
15
16
  envVariables: EnvVariables
16
17
  ) {
17
18
  const post = await queryOneEntity<
@@ -6,12 +6,13 @@ import {
6
6
  } from "@rxdrag/rxcms-models";
7
7
  import { newQueryProductOptions } from "./newQueryProductOptions";
8
8
  import { queryOneEntity } from "./queryOneEntity";
9
- import { EnvVariables, TSize } from "../types";
9
+ import { EnvVariables } from "../types";
10
10
  import { productToViewModel, TProduct } from "../view-model";
11
+ import { ImageSize } from "@rxdrag/rxcms-models";
11
12
 
12
13
  export async function queryOneProductBySlug(
13
14
  slug: string,
14
- imageSize: TSize | undefined,
15
+ imageSize: ImageSize | undefined,
15
16
  envVariables: EnvVariables
16
17
  ) {
17
18
  const product = await queryOneEntity<
@@ -11,10 +11,11 @@ import {
11
11
  UserQueryOptions,
12
12
  UserFields,
13
13
  ProductOrderBy,
14
+ ImageSize,
14
15
  } from "@rxdrag/rxcms-models";
15
16
  import { queryEntityList } from "./queryEntityList";
16
17
  import { ListResult } from "@rxdrag/entify-lib";
17
- import { EnvVariables, TSize } from "../types";
18
+ import { EnvVariables } from "../types";
18
19
  import { TPost } from "../view-model";
19
20
 
20
21
  export interface ListConditions {
@@ -26,7 +27,7 @@ export interface ListConditions {
26
27
 
27
28
  export async function queryPosts(
28
29
  conditions: ListConditions,
29
- coverSize: TSize | undefined,
30
+ coverSize: ImageSize | undefined,
30
31
  envVariables: EnvVariables,
31
32
  selectFields?: (keyof Post)[]
32
33
  ) {
@@ -12,12 +12,13 @@ import { ListConditions } from "./queryPosts";
12
12
  import { queryEntityList } from "./queryEntityList";
13
13
  import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
14
14
  import { ListResult } from "@rxdrag/entify-lib";
15
- import { EnvVariables, TSize } from "../types";
15
+ import { EnvVariables } from "../types";
16
16
  import { TProduct } from "../view-model";
17
+ import { ImageSize } from "@rxdrag/rxcms-models";
17
18
 
18
19
  export async function queryProducts(
19
20
  conditions: ListConditions,
20
- imageSize: TSize | undefined,
21
+ imageSize: ImageSize | undefined,
21
22
  envVariables: EnvVariables,
22
23
  addonFields?: (keyof Product)[]
23
24
  ) {
@@ -1,11 +1,7 @@
1
+ import { ImageSizes } from "@rxdrag/rxcms-models";
1
2
  import { EnvVariables } from "./variables";
2
-
3
- export type TSize = {
4
- width: number
5
- height: number
6
- }
7
-
8
3
  //astro传递上下文用
9
4
  export type Locals = {
10
5
  env: EnvVariables;
6
+ imageSizes: ImageSizes;
11
7
  };
@@ -9,7 +9,6 @@ import {
9
9
  WebsiteSettings,
10
10
  } from "@rxdrag/rxcms-models";
11
11
  import {
12
- TMedia,
13
12
  TMedias,
14
13
  TPost,
15
14
  TPostCategory,
@@ -20,15 +19,6 @@ import {
20
19
  } from "./models";
21
20
  import { ListResult } from "@rxdrag/entify-lib";
22
21
 
23
- export function mediaToViewModel(media?: Media): TMedia | undefined {
24
- if (!media) {
25
- return undefined;
26
- }
27
- return {
28
- ...media,
29
- ...media?.file,
30
- };
31
- }
32
22
 
33
23
  export function mediasToViewModel(product?: Product): TMedias | undefined {
34
24
  if (!product) {
@@ -40,7 +30,7 @@ export function mediasToViewModel(product?: Product): TMedias | undefined {
40
30
  return {
41
31
  alt: mediaOnProduct.altText,
42
32
  seqValue: mediaOnProduct.seqValue,
43
- ...mediaToViewModel(mediaOnProduct.media)!,
33
+ ...mediaOnProduct.media!,
44
34
  };
45
35
  }),
46
36
  };
@@ -48,14 +38,14 @@ export function mediasToViewModel(product?: Product): TMedias | undefined {
48
38
 
49
39
  export function attachmentsToViewModel(
50
40
  attachments?: AttachmentOnProduct[]
51
- ): TMedia[] | undefined {
41
+ ): Media[] | undefined {
52
42
  if (!attachments) {
53
43
  return undefined;
54
44
  }
55
45
  return attachments?.map((attachPovit) => {
56
46
  return {
57
47
  seqValue: attachPovit.seqValue,
58
- ...mediaToViewModel(attachPovit.attachment)!,
48
+ ...attachPovit.attachment!,
59
49
  };
60
50
  });
61
51
  }
@@ -79,19 +69,19 @@ export function productCategoryToViewModel(
79
69
  }
80
70
  return {
81
71
  ...productCategory,
82
- media: productCategory?.media && mediaToViewModel(productCategory?.media),
72
+ media: productCategory?.media,
83
73
  children: productCategory?.children?.length
84
74
  ? (productCategory?.children?.map(productCategoryToViewModel) as
85
- | TProductCategory[]
86
- | undefined)
75
+ | TProductCategory[]
76
+ | undefined)
87
77
  : undefined,
88
78
  parent:
89
79
  productCategory?.parent &&
90
80
  productCategoryToViewModel(productCategory?.parent),
91
81
  products: productCategory?.products?.length
92
82
  ? (productCategory?.products?.map(productToViewModel) as
93
- | TProduct[]
94
- | undefined)
83
+ | TProduct[]
84
+ | undefined)
95
85
  : undefined,
96
86
  };
97
87
  }
@@ -152,11 +142,11 @@ export function postCategoryToViewModel(
152
142
  }
153
143
  return {
154
144
  ...postCategory,
155
- media: postCategory?.media && mediaToViewModel(postCategory?.media),
145
+ media: postCategory?.media,
156
146
  children: postCategory?.children?.length
157
147
  ? (postCategory?.children?.map(postCategoryToViewModel) as
158
- | TPostCategory[]
159
- | undefined)
148
+ | TPostCategory[]
149
+ | undefined)
160
150
  : undefined,
161
151
  parent:
162
152
  postCategory?.parent && postCategoryToViewModel(postCategory?.parent),
@@ -190,7 +180,7 @@ export function postToViewModel(post?: Post): TPost | undefined {
190
180
  content: post?.content,
191
181
  meta: post?.meta,
192
182
  category: post?.category && postCategoryToViewModel(post?.category),
193
- cover: post?.cover && mediaToViewModel(post?.cover),
183
+ cover: post?.cover,
194
184
  };
195
185
  }
196
186
 
@@ -226,7 +216,7 @@ export function userToViewModel(user?: User): TUser | undefined {
226
216
  }
227
217
  return {
228
218
  ...user,
229
- avatar: user?.avatar && mediaToViewModel(user?.avatar),
219
+ avatar: user?.avatar,
230
220
  };
231
221
  }
232
222
 
@@ -241,15 +231,3 @@ export function userListToViewModel(
241
231
  items: users?.items?.map(userToViewModel) as TUser[] | undefined,
242
232
  };
243
233
  }
244
-
245
- export function mediaListToViewModel(
246
- medias?: ListResult<Media>
247
- ): ListResult<TMedia> | undefined {
248
- if (!medias) {
249
- return undefined;
250
- }
251
- return {
252
- ...medias,
253
- items: medias?.items?.map(mediaToViewModel) as TMedia[] | undefined,
254
- };
255
- }
@@ -1,22 +1,8 @@
1
- import { MediaType, PageMeta } from "@rxdrag/rxcms-models";
1
+ import { Media, PageMeta } from "@rxdrag/rxcms-models";
2
2
 
3
- /**
4
- * 定义数据绑定用的类型,需要从@rxdrag/rxcms-models的类型进行转换
5
- */
6
-
7
- export type TMedia = {
8
- id?: string | null;
9
- name?: string;
10
- mimeType?: string;
11
- extName?: string;
12
- thumbnail?: string;
13
- resize?: string;
14
- url?: string;
3
+ export type TMedia = Media & {
15
4
  alt?: string;
16
- createdAt?: Date;
17
- updatedAt?: Date;
18
- mediaType?: MediaType;
19
- };
5
+ }
20
6
 
21
7
  export type TMedias = {
22
8
  externalVideoUrl?: string;
@@ -43,7 +29,7 @@ export type TProduct = {
43
29
  features?: string;
44
30
  medias?: TMedias;
45
31
  //从头medias中获取第一个不是视频的图片
46
- cover?: TMedia;
32
+ cover?: Media;
47
33
  content?: string;
48
34
  content2?: string;
49
35
  content3?: string;
@@ -53,7 +39,7 @@ export type TProduct = {
53
39
  updatedAt?: Date;
54
40
  category?: TProductCategory;
55
41
  related?: TProduct[];
56
- attachments?: TMedia[];
42
+ attachments?: Media[];
57
43
  meta?: PageMeta;
58
44
  };
59
45
 
@@ -62,7 +48,7 @@ export type TPostCategory = {
62
48
  slug?: string;
63
49
  name?: string;
64
50
  children?: TProductCategory[];
65
- media?: TMedia;
51
+ media?: Media;
66
52
  parent?: TProductCategory;
67
53
  posts?: TPost[];
68
54
  };
@@ -70,7 +56,7 @@ export type TPostCategory = {
70
56
  export type TUser = {
71
57
  id?: string | null;
72
58
  name?: string;
73
- avatar?: TMedia;
59
+ avatar?: Media;
74
60
  position?: string;
75
61
  profile?: string;
76
62
  email?: string;
@@ -87,7 +73,7 @@ export type TPost = {
87
73
  slug?: string;
88
74
  title?: string;
89
75
  description?: string;
90
- cover?: TMedia;
76
+ cover?: Media;
91
77
  content?: string;
92
78
  extends?: object;
93
79
  publishedAt?: Date;
@@ -101,7 +87,7 @@ export type TPost = {
101
87
  export type TWebsiteSettings = {
102
88
  id?: string | null;
103
89
  contact?: string;
104
- contactAvatar?: TMedia;
90
+ contactAvatar?: Media;
105
91
  address?: string;
106
92
  email?: string;
107
93
  tel?: string;
@@ -131,6 +117,5 @@ export const entityMaps: Record<string, string> = {
131
117
  Post: "TPost",
132
118
  PostCategory: "TPostCategory",
133
119
  User: "TUser",
134
- Media: "TMedia",
135
120
  WebsiteSettings: "TWebsiteSettings",
136
121
  };
@@ -61,9 +61,7 @@ export const Medias = forwardRef<HTMLDivElement, MediasProps>((props, ref) => {
61
61
  : value.externalVideoUrl.split("v=")[1]?.split("&")[0];
62
62
 
63
63
  if (videoId) {
64
- setThumbnailUrl(
65
- `https://img.youtube.com/vi/${videoId}/default.jpg`
66
- );
64
+ setThumbnailUrl(`https://img.youtube.com/vi/${videoId}/default.jpg`);
67
65
  }
68
66
  }
69
67
  }, [value?.externalVideoUrl]);
@@ -211,7 +209,7 @@ export const Medias = forwardRef<HTMLDivElement, MediasProps>((props, ref) => {
211
209
  )}
212
210
  >
213
211
  <img
214
- src={media?.resize || media?.url}
212
+ src={media?.file?.resize || media?.file?.url}
215
213
  alt={media?.alt}
216
214
  className="w-full h-full object-cover object-center"
217
215
  />
@@ -310,7 +308,7 @@ export const Medias = forwardRef<HTMLDivElement, MediasProps>((props, ref) => {
310
308
  onClick={() => setSelectedId(media.id)}
311
309
  >
312
310
  <img
313
- src={media?.resize || media?.url}
311
+ src={media?.file?.resize || media?.file?.url}
314
312
  alt={media?.alt}
315
313
  className="w-full h-full object-cover"
316
314
  />