glitch-javascript-sdk 0.6.1 → 0.6.2
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/dist/cjs/index.js +100 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Posts.d.ts +21 -0
- package/dist/esm/api/SocialPosts.d.ts +31 -0
- package/dist/esm/api/index.d.ts +2 -0
- package/dist/esm/index.js +100 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routes/SocialPostsRoute.d.ts +7 -0
- package/dist/esm/util/Requests.d.ts +1 -1
- package/dist/index.d.ts +22 -1
- package/package.json +1 -1
- package/src/api/Posts.ts +77 -22
- package/src/api/SocialPosts.ts +46 -0
- package/src/api/index.ts +3 -1
- package/src/index.ts +2 -0
- package/src/routes/SocialPostsRoute.ts +14 -0
- package/src/util/Requests.ts +1 -1
|
@@ -16,7 +16,7 @@ declare class Requests {
|
|
|
16
16
|
static post<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
17
17
|
static put<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
18
18
|
static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
19
|
-
static uploadFile<T>(url: string, filename: string, file: File, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
19
|
+
static uploadFile<T>(url: string, filename: string, file: File | Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
20
20
|
static uploadBlob<T>(url: string, filename: string, blob: Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
21
21
|
static processRoute<T>(route: Route, data?: object, routeReplace?: {
|
|
22
22
|
[key: string]: any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1748,6 +1748,27 @@ declare class Posts {
|
|
|
1748
1748
|
* @returns promise
|
|
1749
1749
|
*/
|
|
1750
1750
|
static createWithBlob<T>(blob: Blob, data?: object): AxiosPromise<Response<T>>;
|
|
1751
|
+
/**
|
|
1752
|
+
* Create a new post with a file divided into chunks.
|
|
1753
|
+
*
|
|
1754
|
+
* @param file The file object to upload.
|
|
1755
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
1756
|
+
* @param data Any additional data to pass along to the upload.
|
|
1757
|
+
*
|
|
1758
|
+
* @returns Promise
|
|
1759
|
+
*/
|
|
1760
|
+
/**
|
|
1761
|
+
* Create a new post with a file divided into chunks.
|
|
1762
|
+
*
|
|
1763
|
+
* @param file The file object to upload.
|
|
1764
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
1765
|
+
* @param data Any additional data to pass along to the upload.
|
|
1766
|
+
*
|
|
1767
|
+
* @returns Promise
|
|
1768
|
+
*/
|
|
1769
|
+
static createWithFileInChunks<T>(file: File, chunkSize?: number, data?: {
|
|
1770
|
+
[key: string]: any;
|
|
1771
|
+
}): Promise<AxiosPromise<Response<T>>>;
|
|
1751
1772
|
/**
|
|
1752
1773
|
* Update a post.
|
|
1753
1774
|
*
|
|
@@ -2069,7 +2090,7 @@ declare class Requests {
|
|
|
2069
2090
|
static post<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2070
2091
|
static put<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2071
2092
|
static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2072
|
-
static uploadFile<T>(url: string, filename: string, file: File, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2093
|
+
static uploadFile<T>(url: string, filename: string, file: File | Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2073
2094
|
static uploadBlob<T>(url: string, filename: string, blob: Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2074
2095
|
static processRoute<T>(route: Route, data?: object, routeReplace?: {
|
|
2075
2096
|
[key: string]: any;
|
package/package.json
CHANGED
package/src/api/Posts.ts
CHANGED
|
@@ -12,7 +12,7 @@ class Posts {
|
|
|
12
12
|
*
|
|
13
13
|
* @returns promise
|
|
14
14
|
*/
|
|
15
|
-
public static list<T>(params?: Record<string, any>)
|
|
15
|
+
public static list<T>(params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
16
16
|
return Requests.processRoute(PostsRoute.routes.list, undefined, undefined, params);
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -25,22 +25,22 @@ class Posts {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns Promise
|
|
27
27
|
*/
|
|
28
|
-
public static create<T>(data
|
|
28
|
+
public static create<T>(data: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
29
29
|
|
|
30
30
|
return Requests.processRoute(PostsRoute.routes.create, data, undefined, params);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Create a new post with a file. The file should either be an image or video.
|
|
35
|
+
*
|
|
36
|
+
* @see https://api.glitch.fun/api/documentation#/Post%20Route/newPostResourceStorage
|
|
37
|
+
*
|
|
38
|
+
* @param file The file object to upload.
|
|
39
|
+
* @param data Any additional data to pass along to the upload.
|
|
40
|
+
*
|
|
41
|
+
* @returns promise
|
|
42
|
+
*/
|
|
43
|
+
public static createWithFile<T>(file: File, data?: object): AxiosPromise<Response<T>> {
|
|
44
44
|
|
|
45
45
|
return Requests.uploadFile(PostsRoute.routes.create.url, 'file', file, data);
|
|
46
46
|
}
|
|
@@ -55,11 +55,66 @@ class Posts {
|
|
|
55
55
|
*
|
|
56
56
|
* @returns promise
|
|
57
57
|
*/
|
|
58
|
-
public static createWithBlob<T>(blob
|
|
58
|
+
public static createWithBlob<T>(blob: Blob, data?: object): AxiosPromise<Response<T>> {
|
|
59
59
|
|
|
60
60
|
return Requests.uploadBlob(PostsRoute.routes.create.url, 'file', blob, data);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Create a new post with a file divided into chunks.
|
|
65
|
+
*
|
|
66
|
+
* @param file The file object to upload.
|
|
67
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
68
|
+
* @param data Any additional data to pass along to the upload.
|
|
69
|
+
*
|
|
70
|
+
* @returns Promise
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Create a new post with a file divided into chunks.
|
|
74
|
+
*
|
|
75
|
+
* @param file The file object to upload.
|
|
76
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
77
|
+
* @param data Any additional data to pass along to the upload.
|
|
78
|
+
*
|
|
79
|
+
* @returns Promise
|
|
80
|
+
*/
|
|
81
|
+
public static async createWithFileInChunks<T>(file: File, chunkSize: number = 1 * 1024 * 1024, data: { [key: string]: any } = {}): Promise<AxiosPromise<Response<T>>> {
|
|
82
|
+
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
83
|
+
let lastResponse: AxiosPromise<Response<T>> | undefined;
|
|
84
|
+
|
|
85
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
86
|
+
const start = i * chunkSize;
|
|
87
|
+
const end = start + chunkSize;
|
|
88
|
+
const chunk = file.slice(start, end);
|
|
89
|
+
|
|
90
|
+
const formData = new FormData();
|
|
91
|
+
formData.append('file', chunk, `${i}-${file.name}`); // Naming chunks as index-filename for identification
|
|
92
|
+
formData.append('totalChunks', totalChunks.toString());
|
|
93
|
+
formData.append('currentChunk', i.toString());
|
|
94
|
+
|
|
95
|
+
// merge any other data if provided
|
|
96
|
+
for (let key in data) {
|
|
97
|
+
formData.append(key, data[key]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// If it's the last chunk, save the response
|
|
101
|
+
if (i === totalChunks - 1) {
|
|
102
|
+
await Requests.uploadFile(PostsRoute.routes.create.url, 'file', chunk, formData);
|
|
103
|
+
} else {
|
|
104
|
+
await Requests.uploadFile(PostsRoute.routes.create.url, 'file', chunk, formData);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!lastResponse) {
|
|
109
|
+
throw new Error("No response from the last chunk upload");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return lastResponse;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
63
118
|
|
|
64
119
|
/**
|
|
65
120
|
* Update a post.
|
|
@@ -71,9 +126,9 @@ class Posts {
|
|
|
71
126
|
*
|
|
72
127
|
* @returns promise
|
|
73
128
|
*/
|
|
74
|
-
public static update<T>(post_id
|
|
129
|
+
public static update<T>(post_id: string, data: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
75
130
|
|
|
76
|
-
return Requests.processRoute(PostsRoute.routes.update, data, {post_id
|
|
131
|
+
return Requests.processRoute(PostsRoute.routes.update, data, { post_id: post_id }, params);
|
|
77
132
|
}
|
|
78
133
|
|
|
79
134
|
/**
|
|
@@ -85,9 +140,9 @@ class Posts {
|
|
|
85
140
|
*
|
|
86
141
|
* @returns promise
|
|
87
142
|
*/
|
|
88
|
-
public static view<T>(post_id
|
|
143
|
+
public static view<T>(post_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
89
144
|
|
|
90
|
-
return Requests.processRoute(PostsRoute.routes.view, {}, {post_id
|
|
145
|
+
return Requests.processRoute(PostsRoute.routes.view, {}, { post_id: post_id }, params);
|
|
91
146
|
}
|
|
92
147
|
|
|
93
148
|
/**
|
|
@@ -98,9 +153,9 @@ class Posts {
|
|
|
98
153
|
* @param post_id The id of the post to delete.
|
|
99
154
|
* @returns promise
|
|
100
155
|
*/
|
|
101
|
-
public static delete<T>(post_id
|
|
156
|
+
public static delete<T>(post_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
102
157
|
|
|
103
|
-
return Requests.processRoute(PostsRoute.routes.delete, {}, {post_id
|
|
158
|
+
return Requests.processRoute(PostsRoute.routes.delete, {}, { post_id: post_id }, params);
|
|
104
159
|
}
|
|
105
160
|
|
|
106
161
|
/**
|
|
@@ -112,9 +167,9 @@ class Posts {
|
|
|
112
167
|
*
|
|
113
168
|
* @returns Promise
|
|
114
169
|
*/
|
|
115
|
-
public static toggleInteraction<T>(post_id
|
|
170
|
+
public static toggleInteraction<T>(post_id: string, data: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
116
171
|
|
|
117
|
-
return Requests.processRoute(PostsRoute.routes.toggleInteraction, data, {post_id
|
|
172
|
+
return Requests.processRoute(PostsRoute.routes.toggleInteraction, data, { post_id: post_id }, params);
|
|
118
173
|
}
|
|
119
174
|
|
|
120
175
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import SocialPostsRoute from "../routes/SocialPostsRoute";
|
|
2
|
+
import Requests from "../util/Requests";
|
|
3
|
+
import Response from "../util/Response";
|
|
4
|
+
import { AxiosPromise } from "axios";
|
|
5
|
+
|
|
6
|
+
class SocialPosts {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* List all the Posts.
|
|
10
|
+
*
|
|
11
|
+
* @see https://api.glitch.fun/api/documentation#/Post%20Route/resourcePostList
|
|
12
|
+
*
|
|
13
|
+
* @returns promise
|
|
14
|
+
*/
|
|
15
|
+
public static list<T>(params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
16
|
+
return Requests.processRoute(SocialPostsRoute.routes.getPosts, undefined, undefined, params);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Give a tip to another user
|
|
21
|
+
*
|
|
22
|
+
* @see https://api.glitch.fun/api/documentation#/Authentication%20Route/authLogin
|
|
23
|
+
*
|
|
24
|
+
* @returns A promise
|
|
25
|
+
*/
|
|
26
|
+
public static create<T>(data? : object, params?: Record<string, any>) : AxiosPromise<Response<T>> {
|
|
27
|
+
return Requests.processRoute(SocialPostsRoute.routes.create, data, {}, params);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve the information for a single post.
|
|
32
|
+
*
|
|
33
|
+
* @see https://api.glitch.fun/api/documentation#/Post%20Route/showPostStorage
|
|
34
|
+
*
|
|
35
|
+
* @param post_id The id fo the post to retrieve.
|
|
36
|
+
*
|
|
37
|
+
* @returns promise
|
|
38
|
+
*/
|
|
39
|
+
public static view<T>(post_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
40
|
+
|
|
41
|
+
return Requests.processRoute(SocialPostsRoute.routes.retrievePost, {}, { post_id: post_id }, params);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default SocialPosts;
|
package/src/api/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import Tips from "./Tips";
|
|
|
13
13
|
import TipEmojis from "./TipEmojis";
|
|
14
14
|
import TipPackages from "./TipPackages";
|
|
15
15
|
import TipPackagePurchases from "./TipPackagePurchases";
|
|
16
|
+
import SocialPosts from "./SocialPosts";
|
|
16
17
|
|
|
17
18
|
export {Auth};
|
|
18
19
|
export {Competitions};
|
|
@@ -28,4 +29,5 @@ export {Utility};
|
|
|
28
29
|
export {Tips};
|
|
29
30
|
export {TipEmojis};
|
|
30
31
|
export {TipPackages};
|
|
31
|
-
export {TipPackagePurchases}
|
|
32
|
+
export {TipPackagePurchases};
|
|
33
|
+
export {SocialPosts};
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Route from "./interface";
|
|
2
|
+
import HTTP_METHODS from "../constants/HttpMethods";
|
|
3
|
+
|
|
4
|
+
class SocialPostsRoute {
|
|
5
|
+
|
|
6
|
+
public static routes: { [key: string]: Route } = {
|
|
7
|
+
getPosts: { url: '/socialposts', method: HTTP_METHODS.GET },
|
|
8
|
+
createPost: { url: '/socialposts', method: HTTP_METHODS.POST },
|
|
9
|
+
retrievePost : { url: '/socialposts/{post_id}', method: HTTP_METHODS.GET },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default SocialPostsRoute;
|