This repository has been archived by the owner on Jul 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
teambition.js
118 lines (111 loc) · 2.81 KB
/
teambition.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
let my_fetch = typeof Deno === 'undefined' ? require("node-fetch") : fetch;
/**
* 获取项目列表
* @param string cookie teambitionCookie
* @return array
*/
async function get_projects(cookie) {
const api = "https://www.teambition.com/api/v2/projects?";
const params = new URLSearchParams({
_organizationId: "000000000000000000000405",
selectBy: "joined",
orderBy: "name",
pageToken: "",
pageSize: "20", // 目前只读取 20 个项目
});
const res = await my_fetch(api + params.toString(), { headers: { cookie } });
return (await res.json()).result;
}
/**
* 获取项目信息
* @param string projectID 项目ID
* @param string cookie teambitionCookie
* @return array
*/
async function get_project(projectID, cookie) {
const api = "https://www.teambition.com/api/projects/" + projectID;
const result = await my_fetch(api, { headers: { cookie } });
return await result.json();
}
/**
* 获取文件夹下的文件夹
* @param string dirid 文件夹ID
* @param string cookie teambitionCookie
* @return array
*/
async function get_dirs(
dirId,
cookie,
count = 100,
order = "updatedDesc",
page = 1
) {
const api = "https://www.teambition.com/api/collections?";
const param = new URLSearchParams({
_parentId: dirId,
order: order,
count: "" + count,
page: "" + page,
});
const result = await my_fetch(api + param.toString(), { headers: { cookie } });
return await result.json();
}
/**
* 获取目录信息
* @param string parentId 目录ID
* @param string cookie teambitionCookie
* @return Object
*/
async function get_dir(parentId, cookie) {
const api = "https://www.teambition.com/api/collections/" + parentId;
const result = await my_fetch(api, { headers: { cookie } });
return await result.json();
}
/**
* 获取文件夹下的文件
* @param string dirid 文件夹ID
* @param string cookie teambitionCookie
* @param int page 页码
* @return array
*/
async function get_files(
dirId,
cookie,
count = 100,
order = "updatedDesc",
page = 1
) {
const api = "https://www.teambition.com/api/works?";
const param = new URLSearchParams({
_parentId: dirId,
order: order,
count: "" + count,
page: "" + page,
});
const result = await my_fetch(api + param.toString(), { headers: { cookie } });
return await result.json();
}
/**
* 获取文件信息
* @param string parentId 文件ID
* @param string cookie teambitionCookie
* @return Object
*/
async function get_file(parentId, cookie) {
const api = "https://www.teambition.com/api/works/" + parentId;
const result = await my_fetch(api, { headers: { cookie } });
const data = await result.json();
if (data["downloadUrl"]) {
return data;
} else {
return false;
}
}
module.exports = {
get_projects,
get_project,
get_dirs,
get_dir,
get_files,
get_file,
};