CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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