Skip to content

Commit

Permalink
update for last ap
Browse files Browse the repository at this point in the history
  • Loading branch information
Xziy committed Oct 27, 2024
1 parent d0d92a9 commit b8faf7f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libs/adminpanel/ProductMediaManager/Items.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export declare class ImageItem extends File<MediaManagerItem> {
}): Promise<void>;
getVariants(id: string): Promise<MediaManagerItem[]>;
uploadVariant(item: MediaManagerItem, file: UploaderFile, fileName: string, group?: string, localeId?: string): Promise<MediaManagerItem>;
getOrirgin(id: string): Promise<string>;
getOrigin(id: string): Promise<string>;
getItems(limit: number, skip: number, sort: string): Promise<{
data: MediaManagerItem[];
next: boolean;
Expand Down
8 changes: 6 additions & 2 deletions libs/adminpanel/ProductMediaManager/Items.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ class ImageItem extends AbstractMediaManager_1.File {
uploadVariant(item, file, fileName, group, localeId) {
throw new Error('Method not implemented.');
}
async getOrirgin(id) {
return path.join(process.cwd(), (await MediaFile.findOne({ where: { id: id }, })).originalFilePath);
async getOrigin(id) {
const mf = await MediaFile.findOne({ where: { id: id } });
if (!mf) {
throw `get origin fail with id: ${id}`;
}
return path.resolve(process.cwd(), mf.originalFilePath || mf.original || '');
}
async getItems(limit, skip, sort) {
let mediaFiles = await MediaFile.find({
Expand Down
9 changes: 7 additions & 2 deletions libs/adminpanel/ProductMediaManager/Items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ export class ImageItem extends File<MediaManagerItem> {
throw new Error('Method not implemented.');
}

public async getOrirgin(id: string): Promise<string> {
return path.join(process.cwd(), (await MediaFile.findOne({ where: { id: id }, })).originalFilePath);
public async getOrigin(id: string): Promise<string> {
const mf = await MediaFile.findOne({ where: { id: id }})
if(!mf){
throw `get origin fail with id: ${id}`
}

return path.resolve(process.cwd(), mf.originalFilePath || mf.original || '');
}

public async getItems(limit: number, skip: number, sort: string): Promise<{ data: MediaManagerItem[]; next: boolean }> {
Expand Down
3 changes: 2 additions & 1 deletion libs/adminpanel/ProductMediaManager/helpers/ConvertType.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ConvertType {
const _type = item.mimeType.split('/')[0];
return {
id: item.id,
original: item.path,
original: `file://${item.path}`,
originalFilePath: item.path,
type: allowedTypes.includes(_type) ? _type : (() => { throw new Error(`Invalid type ${_type}`); })(),
variant: {
origin: item.url
Expand Down
3 changes: 2 additions & 1 deletion libs/adminpanel/ProductMediaManager/helpers/ConvertType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class ConvertType {
const _type = item.mimeType.split('/')[0]
return {
id: item.id,
original: item.path,
original: `file://${item.path}`,
originalFilePath: item.path,
type: allowedTypes.includes(_type) ? _type : (() => { throw new Error(`Invalid type ${_type}`) })(),
variant: {
origin: item.url
Expand Down

0 comments on commit b8faf7f

Please sign in to comment.