Skip to content

Commit

Permalink
feat: update upload imgs
Browse files Browse the repository at this point in the history
  • Loading branch information
wwei-github committed Feb 5, 2024
1 parent 6123ecc commit 3f95c1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/logos/logos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class LogosService {
}

async findAllLogs() {
return this.prismaService.logos.findMany();
return this.prismaService.logos.findMany({ orderBy: { id: 'asc' } });
}
async batchUpdateFile(dtos: { id: number; file: string }[]) {
const transaction = dtos.map((dto) => {
Expand Down
31 changes: 16 additions & 15 deletions src/upload-img/upload-img.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ export class UploadImgService {
}
}

async updateAvatar() {
const builders = await this.logosService.findAllLogs();
const newImgs = builders
.filter((b) => !!b.file)
.map((b) => ({
id: b.id,
file: b.file.replace(
'https://d18wlguog0kde4.cloudfront.net',
'https://cdn.lxdao.io',
),
}));
async updateErrorFiles() {
const logos = await this.logosService.findAllLogs();
const newImgs = logos
.filter((b) => b.file.length > 84 && !b.file.includes('nftstorage.link'))
.map((b) => {
return {
id: b.id,
file: `${b.file.slice(0, 81)}svg`,
};
});
await this.logosService.batchUpdateFile(newImgs);
return { data: newImgs };
}
Expand All @@ -72,7 +71,9 @@ export class UploadImgService {
return false;
}
const contentType = response.headers['content-type'];
const type = contentType.split('/').pop();
const type = contentType.includes('svg')
? 'svg'
: contentType.split('/').pop();

const imgName = `${cid}.${type}`;
fs.writeFileSync(`imgs/${imgName}`, await download(url));
Expand All @@ -88,15 +89,15 @@ export class UploadImgService {
console.log(b.id);
}
});
const newBuidlersImg = (await Promise.all(newImgPromise)).filter(
const newImgs = (await Promise.all(newImgPromise)).filter(
(i) => i && i.id,
) as unknown as {
id: number;
file: string;
}[];
await this.logosService.batchUpdateFile(newBuidlersImg);
await this.logosService.batchUpdateFile(newImgs);
console.log('end');
return { data: newBuidlersImg };
return { data: newImgs };
}

getIpfsCid(ipfsUrl) {
Expand Down

0 comments on commit 3f95c1b

Please sign in to comment.