forked from lcpu-club/overleaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys.controller.js
More file actions
80 lines (72 loc) · 2.66 KB
/
keys.controller.js
File metadata and controls
80 lines (72 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { KeysService } from '../services/keys.service.js';
import {getUserIdentifier} from '../utils/common.js';
export class KeysController {
constructor() {
this.keysService = new KeysService();
}
async saveKey(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
const { name, baseUrl, apiKey } = req.body;
await this.keysService.saveApiKey(userIdentifier, name, baseUrl, apiKey);
res.status(200).json({ success: true });
} catch (error) {
res.status(400).json({ success: false, data: error.message });
}
}
async deleteKey(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
const { name } = req.body;
const result = await this.keysService.deleteApiKey(userIdentifier, name);
res.status(200).json({ success: true, data: result });
} catch (error) {
console.log(error.message)
res.status(400).json({ success: false, data: error.message });
}
}
async getLlmInfo(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
const result = await this.keysService.getLlmInfo(userIdentifier);
res.status(200).json({ success: true, data: result });
} catch (error) {
res.status(400).json({ success: false, data: error.message });
}
}
async getUsingLlm(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
const result = await this.keysService.getUsingLlm(userIdentifier);
res.status(200).json({ success: true, data: result });
} catch (error) {
res.status(400).json({ success: false, data: error.message });
}
}
async updateUsingLlm(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
const { usingLlm } = req.body;
await this.keysService.updateUsingLlm(userIdentifier, usingLlm);
res.status(200).json({ success: true });
} catch (error) {
res.status(400).json({ success: false, data: error.message });
}
}
async updateUsingModel(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
const { name, chatOrCompletion, newModel } = req.body;
await this.keysService.updateUsingModel(userIdentifier, name, chatOrCompletion, newModel);
res.status(200).json({ success: true });
} catch (error) {
res.status(400).json({ success: false, data: error.message });
}
}
}