dashattach 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -2
- package/index.js +1 -1
- package/package.json +4 -1
- package/src/components/actions.js +145 -1
- package/src/components/information.js +3 -2
- package/src/help/apis.js +11 -10
- package/src/help/data.js +2 -1
package/README.md
CHANGED
|
@@ -1,11 +1,79 @@
|
|
|
1
1
|
# DashAttach
|
|
2
2
|
Dashattach - library for interacting with the Dash API.
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
Last version: [0.2.0](https://www.npmjs.com/package/dashattach/v/0.2.0)
|
|
5
|
+
|
|
4
6
|
npm: https://www.npmjs.com/package/dashattach
|
|
5
7
|
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
6
10
|
Installing - `npm i dashattach`
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
### Install and import
|
|
13
|
+
```bash
|
|
14
|
+
npm install dashattach
|
|
15
|
+
```
|
|
9
16
|
```JavaScript (ESM)
|
|
10
17
|
import DashAttach from "dashattach"
|
|
18
|
+
```
|
|
19
|
+
### Login
|
|
20
|
+
```JavaScript
|
|
21
|
+
await DashAttach.auth.login(user, password)
|
|
22
|
+
// Example:
|
|
23
|
+
await DashAttach.auth.login("Dasher", "Password30532")
|
|
24
|
+
// Check is login:
|
|
25
|
+
await DashAttach.auth.myInfo.isLogin()
|
|
26
|
+
// Example:
|
|
27
|
+
if (await DashAttach.auth.myInfo.isLogin()) {
|
|
28
|
+
console.log("You is login in Dash")
|
|
29
|
+
} else {
|
|
30
|
+
console.log("You is not login in Dash")
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
### Get my information
|
|
34
|
+
```JavaScript
|
|
35
|
+
await DashAttach.auth.myInfo.getMyId() // get my id in Dash. Return: number/null
|
|
36
|
+
await DashAttach.auth.myInfo.getMyUsername() // get my username in Dash. Return: string
|
|
37
|
+
await DashAttach.auth.myInfo.getMyMessages() // get my messages in Dash. Return: array
|
|
38
|
+
```
|
|
39
|
+
### Get user information
|
|
40
|
+
```JavaScript
|
|
41
|
+
await DashAttach.info.users.getUsername(id) // get username of user by id. Support: olny number, return: string
|
|
42
|
+
await DashAttach.info.users.getId(username) // get id of user by id. Return: number
|
|
43
|
+
await DashAttach.info.users.getRole(user) // get role of user by id/username. Return: string
|
|
44
|
+
await DashAttach.info.description.getDescription(user) // get description of user by id/username. Return: string
|
|
45
|
+
await DashAttach.info.users.date.join(user) // get join date of user by id/username. Return: string
|
|
46
|
+
await DashAttach.info.users.date.lastActive(user) // get date of last active of user by id/username. Return: string
|
|
47
|
+
await DashAttach.info.users.getLinks(user) // get links of user by id/username. Return: array
|
|
48
|
+
await DashAttach.info.users.getAchievements(user) // get achievements of user by id/username. Return: array
|
|
49
|
+
await DashAttach.info.users.getRecommendedProject(user) // get recommended project of user by id/username. Return: object
|
|
50
|
+
await DashAttach.info.users.getProjects(user, offset, limit) // get projects of user by id/username. Return: array
|
|
51
|
+
await DashAttach.info.users.getFollowers(user, offset, limit) // get followers of user by id/username. Return: array
|
|
52
|
+
await DashAttach.info.users.getFollowing(user, offset, limit) // get following of user by id/username. Return: array
|
|
53
|
+
await DashAttach.info.users.getGradient(user) // get gradient (olny for Dash Supporters) of user by id/username. Return: unknown
|
|
54
|
+
DashAttach.info.users.getAvatar(user) // get avatar url of user by id/username. Return: string
|
|
55
|
+
```
|
|
56
|
+
### Get project information
|
|
57
|
+
```JavaScript
|
|
58
|
+
await DashAttach.info.projects.getName(id) // get name of project. Return: string
|
|
59
|
+
await DashAttach.info.projects.getAuthorId(id) // get id of author of project. Return: number
|
|
60
|
+
await DashAttach.info.projects.getAuthorUsername(id) // get username of author of project. Return: string
|
|
61
|
+
await DashAttach.info.projects.getDescription(id) // get description of project. Return: string
|
|
62
|
+
DashAttach.info.projects.getTrumbnail(id) // get trumbnail user of project. Return: string
|
|
63
|
+
```
|
|
64
|
+
### Actions
|
|
65
|
+
```JavaScript
|
|
66
|
+
await DashAttach.actions.setDescription(description) // set my description
|
|
67
|
+
await DashAttach.actions.uploadAvatar(buffer, filename) // set my avatar
|
|
68
|
+
await DashAttach.actions.follow(user) // follow user
|
|
69
|
+
await DashAttach.actions.unfollow(user) // unfollow user
|
|
70
|
+
await DashAttach.actions.setGradient(gradient) // set gradient. For only Dash Supporters
|
|
71
|
+
await DashAttach.actions.setRecommendedProject(id) // set recommended project
|
|
72
|
+
await DashAttach.actions.addLink(label, url) // add link
|
|
73
|
+
await DashAttach.actions.updateLink(id, label, url) // update link
|
|
74
|
+
await DashAttach.actions.remoweLink(id) // delete link
|
|
75
|
+
```
|
|
76
|
+
### Other
|
|
77
|
+
```JavaScript
|
|
78
|
+
await DashAttach.featuredProjects(offset, limit) // get featured projects. Return: array
|
|
11
79
|
```
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import actions from "./src/components/actions.js"
|
|
|
6
6
|
|
|
7
7
|
const DashAttach = {
|
|
8
8
|
featuredProjects: async (offset, limit) => {
|
|
9
|
-
const result = await (await fetch(`https
|
|
9
|
+
const result = await (await fetch(`https://${DashAttachData.apiUrl}/featured-projects?offset=${+offset || 0}&limit=${+limit || 5}`)).json()
|
|
10
10
|
return result
|
|
11
11
|
},
|
|
12
12
|
auth,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dashattach",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Library for interacting with the Dash API.",
|
|
5
5
|
"homepage": "https://github.com/shaman2016scratch/DashAttach",
|
|
6
6
|
"bugs": {
|
|
@@ -16,5 +16,8 @@
|
|
|
16
16
|
"main": "index.js",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "node test.js"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"form-data": "^4.0.0"
|
|
19
22
|
}
|
|
20
23
|
}
|
|
@@ -1,7 +1,151 @@
|
|
|
1
1
|
import { getSessionDash, checkIsLogin } from "../help/apis.js"
|
|
2
|
+
import { DashAttachData } from "../help/data.js"
|
|
3
|
+
import FormData from 'form-data';
|
|
2
4
|
|
|
3
5
|
const actions = {
|
|
4
|
-
profile: {
|
|
6
|
+
profile: {
|
|
7
|
+
setDescription: async (value) => {
|
|
8
|
+
const imIsLogin = await checkIsLogin()
|
|
9
|
+
if (imIsLogin) {
|
|
10
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/set-description`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
credentials: true,
|
|
13
|
+
body: JSON.stringify({
|
|
14
|
+
description: value
|
|
15
|
+
})
|
|
16
|
+
})).json()
|
|
17
|
+
return res
|
|
18
|
+
} else {
|
|
19
|
+
console.log("Please, login!")
|
|
20
|
+
return {}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
uploadAvatar: async (file, filename) => {
|
|
24
|
+
const imIsLogin = await checkIsLogin()
|
|
25
|
+
if (imIsLogin) {
|
|
26
|
+
const BODY = new FormData()
|
|
27
|
+
BODY.append('file', file, { filename })
|
|
28
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/upload-avatar`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
credentials: true,
|
|
31
|
+
body: BODY
|
|
32
|
+
})).json()
|
|
33
|
+
return res
|
|
34
|
+
} else {
|
|
35
|
+
console.log("Please, login!")
|
|
36
|
+
return {}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
follow: async (target) => {
|
|
40
|
+
const imIsLogin = await checkIsLogin()
|
|
41
|
+
if (imIsLogin) {
|
|
42
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/${target}/follow`, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
credentials: true
|
|
45
|
+
})).json()
|
|
46
|
+
return res
|
|
47
|
+
} else {
|
|
48
|
+
console.log("Please, login!")
|
|
49
|
+
return {}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
unfollow: async (target) => {
|
|
53
|
+
const imIsLogin = await checkIsLogin()
|
|
54
|
+
if (imIsLogin) {
|
|
55
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/${target}/unfollow`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
credentials: true
|
|
58
|
+
})).json()
|
|
59
|
+
return res
|
|
60
|
+
} else {
|
|
61
|
+
console.log("Please, login!")
|
|
62
|
+
return {}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
setGradient: async (gradient) => {
|
|
66
|
+
const imIsLogin = await checkIsLogin()
|
|
67
|
+
if (imIsLogin) {
|
|
68
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/set-gradient`, {
|
|
69
|
+
method: "POST",
|
|
70
|
+
credentials: true,
|
|
71
|
+
body: JSON.stringify({
|
|
72
|
+
gradiend
|
|
73
|
+
})
|
|
74
|
+
})).json()
|
|
75
|
+
return res
|
|
76
|
+
} else {
|
|
77
|
+
console.log("Please, login!")
|
|
78
|
+
return {}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
setRecommendedProject: async (projectId) => {
|
|
82
|
+
const imIsLogin = await checkIsLogin()
|
|
83
|
+
if (imIsLogin) {
|
|
84
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/set-recommended-project`, {
|
|
85
|
+
method: "POST",
|
|
86
|
+
credentials: true,
|
|
87
|
+
body: JSON.stringify({
|
|
88
|
+
projectId
|
|
89
|
+
})
|
|
90
|
+
})).json()
|
|
91
|
+
return res
|
|
92
|
+
} else {
|
|
93
|
+
console.log("Please, login!")
|
|
94
|
+
return {}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
addLink: async (label, url) => {
|
|
98
|
+
const imIsLogin = await checkIsLogin()
|
|
99
|
+
if (imIsLogin) {
|
|
100
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/add-link`, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
credentials: true,
|
|
103
|
+
body: JSON.stringify({
|
|
104
|
+
label,
|
|
105
|
+
link: url
|
|
106
|
+
})
|
|
107
|
+
})).json()
|
|
108
|
+
return res
|
|
109
|
+
} else {
|
|
110
|
+
console.log("Please, login!")
|
|
111
|
+
return {}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
updateLink: async (id, label, url) => {
|
|
115
|
+
const imIsLogin = await checkIsLogin()
|
|
116
|
+
if (imIsLogin) {
|
|
117
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/update-link`, {
|
|
118
|
+
method: "POST",
|
|
119
|
+
credentials: true,
|
|
120
|
+
body: JSON.stringify({
|
|
121
|
+
linkIndex: id,
|
|
122
|
+
label,
|
|
123
|
+
link: url
|
|
124
|
+
})
|
|
125
|
+
})).json()
|
|
126
|
+
return res
|
|
127
|
+
} else {
|
|
128
|
+
console.log("Please, login!")
|
|
129
|
+
return {}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
remoweLink: async (id) => {
|
|
133
|
+
const imIsLogin = await checkIsLogin()
|
|
134
|
+
if (imIsLogin) {
|
|
135
|
+
const res = await (await fetch(`https://${DashAttachData.apiUrl}/users/remowe-link`, {
|
|
136
|
+
method: "POST",
|
|
137
|
+
credentials: true,
|
|
138
|
+
body: JSON.stringify({
|
|
139
|
+
linkIndex: id
|
|
140
|
+
})
|
|
141
|
+
})).json()
|
|
142
|
+
return res
|
|
143
|
+
} else {
|
|
144
|
+
console.log("Please, login!")
|
|
145
|
+
return {}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
5
149
|
}
|
|
6
150
|
|
|
7
151
|
export default actions
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getDashUser, getDashProject, getDashUserProjects, getDashUserFollowers, getDashUserFollowing } from "../help/apis.js"
|
|
2
|
+
import { DashAttachData } from "../help/data.js"
|
|
2
3
|
|
|
3
4
|
const info = {
|
|
4
5
|
users: {
|
|
@@ -62,7 +63,7 @@ const info = {
|
|
|
62
63
|
return result?.profile?.gradient || null
|
|
63
64
|
},
|
|
64
65
|
getAvatar: (user) => {
|
|
65
|
-
return `https
|
|
66
|
+
return `https://${DashAttachData.apiUrl}/users/avatars/${user}`
|
|
66
67
|
}
|
|
67
68
|
},
|
|
68
69
|
projects: {
|
|
@@ -83,7 +84,7 @@ const info = {
|
|
|
83
84
|
return result?.description || ""
|
|
84
85
|
},
|
|
85
86
|
getTrumbnail: (project) => {
|
|
86
|
-
return `https
|
|
87
|
+
return `https://${DashAttachData.apiUrl}/projects/trumbnails/${project}`
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
}
|
package/src/help/apis.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { DashAttachData, setDashAttachData } from "../help/data.js"
|
|
2
2
|
|
|
3
3
|
const checkIsLogin = async () => {
|
|
4
|
-
const req = await fetch(
|
|
4
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/session`, {
|
|
5
5
|
credentials: "include"
|
|
6
6
|
})
|
|
7
|
+
const res = await req.json()
|
|
7
8
|
let returN = false
|
|
8
|
-
if (
|
|
9
|
+
if (res.ok) {
|
|
9
10
|
returN = true
|
|
10
11
|
}
|
|
11
12
|
return returN
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
const singinDash = async (userId, password) => {
|
|
15
|
-
const req = await fetch(
|
|
16
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/auth/login`, {
|
|
16
17
|
credentials: "include",
|
|
17
18
|
method: "POST",
|
|
18
19
|
headers: {
|
|
@@ -31,7 +32,7 @@ const singinDash = async (userId, password) => {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
const getSessionDash = async () => {
|
|
34
|
-
const req = await fetch(
|
|
35
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/session`, {
|
|
35
36
|
credentials: "include"
|
|
36
37
|
})
|
|
37
38
|
const res = await req.json()
|
|
@@ -39,37 +40,37 @@ const getSessionDash = async () => {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const getDashUser = async (user) => {
|
|
42
|
-
const req = await fetch(`https
|
|
43
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/users/${user}`)
|
|
43
44
|
const res = await req.json()
|
|
44
45
|
return res.user
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
const getDashProject = async (project) => {
|
|
48
|
-
const req = await fetch(`https
|
|
49
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/projects/${project}`)
|
|
49
50
|
const res = await req.json()
|
|
50
51
|
return res.project
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
const getDashUserProjects = async (user, offset, limit) => {
|
|
54
|
-
const req = await fetch(`https
|
|
55
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/users/${user}/projects?offset=${offset}&limit=${limit}`)
|
|
55
56
|
const res = await req.json()
|
|
56
57
|
return res.projects
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
const getDashUserFollowers = async (user, offset, limit) => {
|
|
60
|
-
const req = await fetch(`https
|
|
61
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/users/${user}/followers?offset=${offset}&limit=${limit}`)
|
|
61
62
|
const res = await req.json()
|
|
62
63
|
return res.followers
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
const getDashUserFollowing = async (user, offset, limit) => {
|
|
66
|
-
const req = await fetch(`https
|
|
67
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/users/${user}/following?offset=${offset}&limit=${limit}`)
|
|
67
68
|
const res = await req.json()
|
|
68
69
|
return res.following
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
const getSessionMessagesDash = async () => {
|
|
72
|
-
const req = await fetch(
|
|
73
|
+
const req = await fetch(`https://${DashAttachData.apiUrl}/session/messages`, {
|
|
73
74
|
credentials: "include"
|
|
74
75
|
})
|
|
75
76
|
const res = await req.json()
|