dashattach 0.0.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # DashAttach
2
2
  Dashattach - library for interacting with the Dash API.
3
3
 
4
- Last version: 0.0.3
4
+ Last version: [0.2.0](https://www.npmjs.com/package/dashattach/v/0.2.0)
5
5
 
6
6
  npm: https://www.npmjs.com/package/dashattach
7
7
 
@@ -61,6 +61,18 @@ await DashAttach.info.projects.getAuthorUsername(id) // get username of author o
61
61
  await DashAttach.info.projects.getDescription(id) // get description of project. Return: string
62
62
  DashAttach.info.projects.getTrumbnail(id) // get trumbnail user of project. Return: string
63
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
+ ```
64
76
  ### Other
65
77
  ```JavaScript
66
78
  await DashAttach.featuredProjects(offset, limit) // get featured projects. Return: array
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://api.dashblocks.org/featured-projects?offset=${+offset || 0}&limit=${+limit || 5}`)).json()
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",
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://api.dashblocks.org/users/avatars/${user}`
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://api.dashblocks.org/projects/trumbnails/${project}`
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("https://api.dashblocks.org/session", {
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 (req.ok) {
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("https://api.dashblocks.org/auth/login", {
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("https://api.dashblocks.org/session", {
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://api.dashblocks.org/users/${user}`)
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://api.dashblocks.org/projects/${project}`)
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://api.dashblocks.org/users/${user}/projects?offset=${offset}&limit=${limit}`)
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://api.dashblocks.org/users/${user}/followers?offset=${offset}&limit=${limit}`)
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://api.dashblocks.org/users/${user}/following?offset=${offset}&limit=${limit}`)
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("https://api.dashblocks.org/session/messages", {
73
+ const req = await fetch(`https://${DashAttachData.apiUrl}/session/messages`, {
73
74
  credentials: "include"
74
75
  })
75
76
  const res = await req.json()
package/src/help/data.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const DashAttachDataDefault = {
2
- isLogin: false
2
+ isLogin: false,
3
+ apiUrl: "api.dashblocks.org"
3
4
  }
4
5
 
5
6
  let DashAttachData = DashAttachDataDefault