Commit ccbcaee7 authored by nanahira's avatar nanahira

Update console-api/src/update/update.service.ts, console-api/src/s3/s3.service.ts files

parent 0e12bf1c
Pipeline #39019 passed with stages
in 3 minutes and 18 seconds
...@@ -63,17 +63,33 @@ export class S3Service extends ConsoleLogger { ...@@ -63,17 +63,33 @@ export class S3Service extends ConsoleLogger {
return this.s3.send(command); return this.s3.send(command);
} }
async removeObjects(paths: string[]) { async removeObjects(paths: string[]) {
const CHUNK_SIZE = 1000;
// 按 1000 一组分割
const chunks = [];
for (let i = 0; i < paths.length; i += CHUNK_SIZE) {
chunks.push(paths.slice(i, i + CHUNK_SIZE));
}
// 顺序执行每组删除
for (const chunk of chunks) {
const command = new DeleteObjectsCommand({ const command = new DeleteObjectsCommand({
Bucket: this.bucket, Bucket: this.bucket,
Delete: { Delete: {
Objects: paths.map((path) => ({ Objects: chunk.map((path) => ({
Key: this.getPathWithPrefix(path), Key: this.getPathWithPrefix(path),
})), })),
}, },
}); });
return this.s3.send(command);
try {
await this.s3.send(command);
} catch(e) {
this.error(`Failed to remove ${chunk.length} S3 objects: ${e}`);
}
} }
}
async fileExists(path: string) { async fileExists(path: string) {
// const objects = await this.listObjects(path); // const objects = await this.listObjects(path);
......
...@@ -11,6 +11,7 @@ import _ from 'lodash'; ...@@ -11,6 +11,7 @@ import _ from 'lodash';
import { AppsJson } from '../utility/apps-json-type'; import { AppsJson } from '../utility/apps-json-type';
import { MirrorService } from '../mirror/mirror.service'; import { MirrorService } from '../mirror/mirror.service';
import Platform = AppsJson.Platform; import Platform = AppsJson.Platform;
import moment from 'moment';
@Injectable() @Injectable()
export class UpdateService extends ConsoleLogger { export class UpdateService extends ConsoleLogger {
...@@ -48,7 +49,7 @@ export class UpdateService extends ConsoleLogger { ...@@ -48,7 +49,7 @@ export class UpdateService extends ConsoleLogger {
const latestBuild = await this.db const latestBuild = await this.db
.getRepository(Build) .getRepository(Build)
.createQueryBuilder('build') .createQueryBuilder('build')
.select(['build.version', 'build.id', 'depot.platform']) .select(['build.createTime', 'build.version', 'build.id', 'depot.platform'])
.innerJoin('build.depot', 'depot') .innerJoin('build.depot', 'depot')
.where('depot.appId = :appId', { appId: app.id }) .where('depot.appId = :appId', { appId: app.id })
.andWhere( .andWhere(
...@@ -70,6 +71,7 @@ export class UpdateService extends ConsoleLogger { ...@@ -70,6 +71,7 @@ export class UpdateService extends ConsoleLogger {
appVersionCacheMap.set(app.id, latestVersion); appVersionCacheMap.set(app.id, latestVersion);
} }
app.version[platform] = latestVersion; app.version[platform] = latestVersion;
app.updated_at = moment(latestBuild.createTime).add(moment().utcOffset(), 'minutes').format('YYYY-MM-DD HH:mm:ss');
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment