Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/accounts/profile.ts
1452 views
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
import { apiRoute, apiRouteOperation } from "lib/api";
14
import {
15
AccountProfileInputSchema,
16
AccountProfileOutputSchema,
17
} from "lib/api/schema/accounts/profile";
18
19
async function handle(req, res) {
20
const { account_id, noCache } = getParams(req);
21
try {
22
if (account_id == null) {
23
res.json({ profile: await getPrivate(req, noCache) });
24
} else {
25
res.json({ profile: await getProfile(account_id, noCache) });
26
}
27
} catch (err) {
28
res.json({ error: err.message });
29
}
30
}
31
32
async function getPrivate(req, noCache) {
33
const account_id = await getAccountId(req, { noCache });
34
if (account_id == null) {
35
return {};
36
}
37
return await getPrivateProfile(account_id, noCache);
38
}
39
40
export default apiRoute({
41
profile: apiRouteOperation({
42
method: "POST",
43
openApiOperation: {
44
tags: ["Accounts"],
45
},
46
})
47
.input({
48
contentType: "application/json",
49
body: AccountProfileInputSchema,
50
})
51
.outputs([
52
{
53
status: 200,
54
contentType: "application/json",
55
body: AccountProfileOutputSchema,
56
},
57
])
58
.handler(handle),
59
});
60
61