UNPKG

@buttercup/googledrive-client

Version:
37 lines (36 loc) 1.09 kB
import { Layerr } from "layerr"; import { handleBadResponse } from "../request.js"; import { MIME_FOLDER, URL_CREATE_DIRECTORY } from "../symbols.js"; export async function createDirectory(options) { const { parentID, patcher, name, token } = options; const parents = parentID ? [parentID] : []; const config = { url: URL_CREATE_DIRECTORY, method: "POST", query: { supportsAllDrives: "true" }, headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }, body: JSON.stringify({ mimeType: MIME_FOLDER, name, parents }) }; const response = await patcher.execute("request", config); handleBadResponse(response); const { id } = (await response.json()); if (!id) { throw new Layerr({ info: { name, parents, url: URL_CREATE_DIRECTORY } }, "Failed creating directory: No new directory ID returned"); } return id; }