Path: blob/master/src/packages/next/pages/api/v2/accounts/profile.ts
1452 views
/*1Get the *public* profile for a given account or the private profile of the2user making the request.34This is public information if user the user knows the account_id. It is the5color, the name, and the image.6*/78import getProfile from "@cocalc/server/accounts/profile/get";9import getPrivateProfile from "@cocalc/server/accounts/profile/private";10import getAccountId from "lib/account/get-account";11import getParams from "lib/api/get-params";12import { apiRoute, apiRouteOperation } from "lib/api";13import {14AccountProfileInputSchema,15AccountProfileOutputSchema,16} from "lib/api/schema/accounts/profile";1718async function handle(req, res) {19const { account_id, noCache } = getParams(req);20try {21if (account_id == null) {22res.json({ profile: await getPrivate(req, noCache) });23} else {24res.json({ profile: await getProfile(account_id, noCache) });25}26} catch (err) {27res.json({ error: err.message });28}29}3031async function getPrivate(req, noCache) {32const account_id = await getAccountId(req, { noCache });33if (account_id == null) {34return {};35}36return await getPrivateProfile(account_id, noCache);37}3839export default apiRoute({40profile: apiRouteOperation({41method: "POST",42openApiOperation: {43tags: ["Accounts"],44},45})46.input({47contentType: "application/json",48body: AccountProfileInputSchema,49})50.outputs([51{52status: 200,53contentType: "application/json",54body: AccountProfileOutputSchema,55},56])57.handler(handle),58});596061