mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 00:00:26 +00:00
Introduces src/core/data/webapi.ts with utilities for chunked group album uploads, including session creation and chunk management. Refactors NTQQWebApi in webapi.ts to use these utilities, adds getAlbumList and uploadImageToQunAlbum methods, and improves upload logic for efficiency and maintainability.
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { uriToLocalFile } from '@/common/file';
|
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|
import { ActionName } from '@/onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
import { existsSync } from 'node:fs';
|
|
import { unlink } from 'node:fs/promises';
|
|
|
|
const SchemaData = Type.Object({
|
|
group_id: Type.String(),
|
|
album_id: Type.String(),
|
|
album_name: Type.String(),
|
|
file: Type.String()
|
|
});
|
|
|
|
type Payload = Static<typeof SchemaData>;
|
|
|
|
export class UploadImageToQunAlbum extends OneBotAction<Payload, unknown> {
|
|
override actionName = ActionName.UploadImageToQunAlbum;
|
|
override payloadSchema = SchemaData;
|
|
|
|
async _handle(payload: Payload) {
|
|
const downloadResult = await uriToLocalFile(this.core.NapCatTempPath, payload.file);
|
|
try {
|
|
return await this.core.apis.WebApi.uploadImageToQunAlbum(payload.group_id, payload.album_id, payload.album_name, downloadResult.path);
|
|
} finally {
|
|
if (downloadResult.path && existsSync(downloadResult.path)) {
|
|
await unlink(downloadResult.path);
|
|
}
|
|
}
|
|
}
|
|
}
|