Skip to content

Commit

Permalink
fix: napcat 群文件上传
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Dec 15, 2024
1 parent b970a83 commit 11ea228
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions main/src/client/NapCatClient/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,27 @@ export class NapCatFriend extends NapCatUser implements Friend {
}
}

class NapCatGFS implements GroupFs {
public constructor(private client: NapCatClient, private gid: number) {
}

async upload(file: string | Buffer | Uint8Array, pid?: string, name?: string, callback?: (percentage: string) => void) {
if (typeof file !== 'string') {
throw new Error('TODO');
}
return await this.client.callApi('upload_group_file', {
group_id: this.gid,
file,
name,
folder_id: pid,
});
}
}

export class NapCatGroup extends NapCatEntity implements Group {
readonly dm = false;
name: string;
fs: GroupFs;

is_owner = false;
is_admin = false;
Expand All @@ -179,6 +197,7 @@ export class NapCatGroup extends NapCatEntity implements Group {
public readonly gid: number) {
super(client);
this.logger = getLogger(`NapCatGroup - ${client.id} - ${gid}`);
this.fs = new NapCatGFS(client, gid);
}

public static async create(client: NapCatClient, gid: number) {
Expand Down Expand Up @@ -248,20 +267,6 @@ export class NapCatGroup extends NapCatEntity implements Group {
}
}

fs: GroupFs = {
async upload(file: string | Buffer | Uint8Array, pid?: string, name?: string, callback?: (percentage: string) => void) {
if (typeof file !== 'string') {
throw new Error('TODO');
}
return await this.client.callApi('upload_group_file', {
group_id: this.gid,
file,
name,
folder_id: pid,
});
},
};

async getAllMemberInfo() {
// lib bug
return await this.client.callApi('get_group_member_list', { group_id: this.gid }) as unknown as WSSendReturn['get_group_member_info'][];
Expand Down

0 comments on commit 11ea228

Please sign in to comment.