Path: blob/master/src/packages/next/pages/api/v2/projects/write-text-file.ts
1451 views
/* Write a text file to a project. */12import getAccountId from "lib/account/get-account";3import getParams from "lib/api/get-params";4import { isValidUUID } from "@cocalc/util/misc";5import callProject from "@cocalc/server/projects/call";6import { OkStatus } from "lib/api/status";78export default async function handle(req, res) {9const account_id = await getAccountId(req);10try {11if (account_id == null) throw Error("must be authenticated");12const { project_id, path, content } = getParams(req);13if (!isValidUUID(project_id))14throw Error("must set project_id to a valid uuid");15if (!path) throw Error("must specify a 'path'");16if (content == null) throw Error("must include content of file");17await callProject({18account_id,19project_id,20mesg: {21event: "write_text_file_to_project",22path,23content,24},25});26res.json(OkStatus);27} catch (err) {28res.json({ error: err.message });29}30}313233