Skip to content

Commit

Permalink
feat: show public asset
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfulyang authored and powerfulyang committed Apr 2, 2024
1 parent dea0886 commit f7cd59b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/asset/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
Expand All @@ -324,7 +328,7 @@ export class AssetService extends BaseService {
async infiniteQuery(params: InfiniteQueryParams<AuthorizationParams> = {}) {
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,
Expand All @@ -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,
},
Expand Down

0 comments on commit f7cd59b

Please sign in to comment.