{"version":3,"file":"files.cjs","names":[],"sources":["../../../../src/rest/commands/create/files.ts"],"sourcesContent":["import type { DirectusFile } from '../../../schema/file.js';\nimport type { ApplyQueryFields, NestedPartial, Query } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\n\nexport type CreateFileOutput<\n\tSchema,\n\tTQuery extends Query<Schema, Item>,\n\tItem extends object = DirectusFile<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\n\n/**\n * Upload/create a new file.\n *\n * @param data Formdata object\n * @param query The query parameters\n *\n * @returns Returns the file object for the uploaded file, or an array of file objects if multiple files were uploaded at once.\n */\nexport const uploadFiles =\n\t<Schema, const TQuery extends Query<Schema, DirectusFile<Schema>>>(\n\t\tdata: FormData,\n\t\tquery?: TQuery,\n\t): RestCommand<CreateFileOutput<Schema, TQuery>, Schema> =>\n\t() => ({\n\t\tpath: '/files',\n\t\tmethod: 'POST',\n\t\tbody: data,\n\t\tparams: query ?? {},\n\t\theaders: { 'Content-Type': 'multipart/form-data' },\n\t});\n\n/**\n * Import a file from the web\n *\n * @param url The url to import the file from\n * @param data Formdata object\n * @param query The query parameters\n *\n * @returns Returns the file object for the imported file.\n */\nexport const importFile =\n\t<Schema, TQuery extends Query<Schema, DirectusFile<Schema>>>(\n\t\turl: string,\n\t\tdata?: NestedPartial<DirectusFile<Schema>>,\n\t\tquery?: TQuery,\n\t): RestCommand<CreateFileOutput<Schema, TQuery>, Schema> =>\n\t() => ({\n\t\tpath: '/files/import',\n\t\tmethod: 'POST',\n\t\tbody: JSON.stringify({ url, data: data ?? {} }),\n\t\tparams: query ?? {},\n\t});\n"],"mappings":"AAkBA,MAAa,GAEX,EACA,SAEM,CACN,KAAM,SACN,OAAQ,OACR,KAAM,EACN,OAAQ,GAAS,EAAE,CACnB,QAAS,CAAE,eAAgB,sBAAuB,CAClD,EAWW,GAEX,EACA,EACA,SAEM,CACN,KAAM,gBACN,OAAQ,OACR,KAAM,KAAK,UAAU,CAAE,MAAK,KAAM,GAAQ,EAAE,CAAE,CAAC,CAC/C,OAAQ,GAAS,EAAE,CACnB"}