Инвойсы на Drive: раскладка как в «07. Invoices» (Инвойсы / способ оплаты / Месяц ГГГГ / «$сумма Вендор.pdf»), перенос оплаченных; drive_folder
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -106,6 +106,20 @@ export class DriveClient implements DriveStore {
|
||||
return (await res.json()) as { name: string; mimeType: string };
|
||||
}
|
||||
|
||||
/** Переносит файл в другую папку (и при необходимости переименовывает). */
|
||||
async move(fileId: string, folderId: string, newName?: string): Promise<void> {
|
||||
const id = encodeURIComponent(fileId);
|
||||
const cur = (await (await this.call(`${API}/files/${id}?fields=parents&supportsAllDrives=true`)).json()) as { parents?: string[] };
|
||||
const params = new URLSearchParams({ addParents: folderId, supportsAllDrives: "true", fields: "id" });
|
||||
const remove = (cur.parents ?? []).filter((p) => p !== folderId);
|
||||
if (remove.length) params.set("removeParents", remove.join(","));
|
||||
await this.call(`${API}/files/${id}?${params}`, {
|
||||
method: "PATCH",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(newName ? { name: newName } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
async download(fileId: string): Promise<Buffer> {
|
||||
const res = await this.call(`${API}/files/${encodeURIComponent(fileId)}?alt=media&supportsAllDrives=true`);
|
||||
return Buffer.from(await res.arrayBuffer());
|
||||
|
||||
Reference in New Issue
Block a user