From f7cd59b809476762101d793918134b8554e1b44f Mon Sep 17 00:00:00 2001 From: powerfulyang Date: Tue, 2 Apr 2024 09:54:11 +0800 Subject: [PATCH] feat: show public asset --- src/asset/asset.service.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/asset/asset.service.ts b/src/asset/asset.service.ts index 6b086b2d..e0b2892c 100644 --- a/src/asset/asset.service.ts +++ b/src/asset/asset.service.ts @@ -35,6 +35,7 @@ import sharp from 'sharp'; import { DataSource, In, Not, Repository } from 'typeorm'; import fetch from 'node-fetch'; import { join } from 'node:path'; +import _ from 'lodash'; @Injectable() export class AssetService extends BaseService { @@ -287,10 +288,13 @@ export class AssetService extends BaseService { const undoes: PinterestInterface[] = await this.fetchUndoes(bucketName); this.logger.info(`[${bucketName}]: undoes count is ${undoes.length}`); + + const botUser = await this.userService.getAssetBotUser(); + for (const undo of undoes.reverse()) { this.logger.info(`[${bucketName}]: ${undo.id}\n${undo.imgList.join('\n')}`); // check if the asset sn is already exist - const existingAsset = await this.assetDao.exist({ + const existingAsset = await this.assetDao.exists({ where: { sn: undo.id, }, @@ -305,7 +309,7 @@ export class AssetService extends BaseService { await this.processAsset(buffer, { bucketName: bucket.name, - uploadBy: await this.userService.getAssetBotUser(), + uploadBy: botUser, async: true, assetAddition: { sn: undo.id, @@ -324,7 +328,7 @@ export class AssetService extends BaseService { async infiniteQuery(params: InfiniteQueryParams = {}) { const { userIds = [], prevCursor, nextCursor } = params; const take = this.formatInfiniteTake(params.take); - const BotUser = await this.userService.getAssetBotUser(); + const { publicBucketIds, publicUserIds } = await this.listPublicAssetSource(); const cursor = this.generateInfiniteCursor({ nextCursor, prevCursor, @@ -347,7 +351,10 @@ export class AssetService extends BaseService { }, where: { uploadBy: { - id: In(userIds.concat(BotUser.id)), + id: In(userIds.concat(_.map(publicUserIds, 'id'))), + }, + bucket: { + id: In(_.map(publicBucketIds, 'id')), }, id: cursor, },