curtain-web-api 1.0.82 → 1.0.84
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { User } from "./curtain-user";
|
|
2
2
|
import axios, { AxiosHeaders } from "axios";
|
|
3
|
+
import jsSHA from "jssha";
|
|
3
4
|
import { arrayBufferToBase64String, base64ToArrayBuffer, decodeJWTPayload, encryptAESData, encryptAESKey, exportAESKey, generateAESKey } from "./curtain-encryption";
|
|
4
5
|
const base = "https://celsus.muttsu.xyz/";
|
|
5
6
|
export const replacer = (key, value) => {
|
|
@@ -740,16 +741,16 @@ export class CurtainWebAPI {
|
|
|
740
741
|
formData.append('curtain_type', request.curtain_type);
|
|
741
742
|
}
|
|
742
743
|
if (request.permanent !== undefined) {
|
|
743
|
-
formData.append('permanent', request.permanent
|
|
744
|
+
formData.append('permanent', request.permanent ? 'True' : 'False');
|
|
744
745
|
}
|
|
745
746
|
if (request.encrypted !== undefined) {
|
|
746
|
-
formData.append('encrypted', request.encrypted
|
|
747
|
+
formData.append('encrypted', request.encrypted ? 'True' : 'False');
|
|
747
748
|
}
|
|
748
749
|
if (request.expiry_duration !== undefined) {
|
|
749
750
|
formData.append('expiry_duration', request.expiry_duration.toString());
|
|
750
751
|
}
|
|
751
752
|
if (request.enable !== undefined) {
|
|
752
|
-
formData.append('enable', request.enable
|
|
753
|
+
formData.append('enable', request.enable ? 'True' : 'False');
|
|
753
754
|
}
|
|
754
755
|
const url = uploadId
|
|
755
756
|
? `${this.baseURL}curtain-chunked-upload/${uploadId}/`
|
|
@@ -778,6 +779,9 @@ export class CurtainWebAPI {
|
|
|
778
779
|
if (request?.md5) {
|
|
779
780
|
formData.append('md5', request.md5);
|
|
780
781
|
}
|
|
782
|
+
if (request?.sha256) {
|
|
783
|
+
formData.append('sha256', request.sha256);
|
|
784
|
+
}
|
|
781
785
|
if (request?.name) {
|
|
782
786
|
formData.append('name', request.name);
|
|
783
787
|
}
|
|
@@ -788,16 +792,16 @@ export class CurtainWebAPI {
|
|
|
788
792
|
formData.append('curtain_type', request.curtain_type);
|
|
789
793
|
}
|
|
790
794
|
if (request?.permanent !== undefined) {
|
|
791
|
-
formData.append('permanent', request.permanent
|
|
795
|
+
formData.append('permanent', request.permanent ? 'True' : 'False');
|
|
792
796
|
}
|
|
793
797
|
if (request?.encrypted !== undefined) {
|
|
794
|
-
formData.append('encrypted', request.encrypted
|
|
798
|
+
formData.append('encrypted', request.encrypted ? 'True' : 'False');
|
|
795
799
|
}
|
|
796
800
|
if (request?.expiry_duration !== undefined) {
|
|
797
801
|
formData.append('expiry_duration', request.expiry_duration.toString());
|
|
798
802
|
}
|
|
799
803
|
if (request?.enable !== undefined) {
|
|
800
|
-
formData.append('enable', request.enable
|
|
804
|
+
formData.append('enable', request.enable ? 'True' : 'False');
|
|
801
805
|
}
|
|
802
806
|
if (request?.curtain_id !== undefined) {
|
|
803
807
|
formData.append('curtain_id', request.curtain_id.toString());
|
|
@@ -807,7 +811,7 @@ export class CurtainWebAPI {
|
|
|
807
811
|
}
|
|
808
812
|
let headers = new AxiosHeaders();
|
|
809
813
|
headers["Accept"] = "application/json";
|
|
810
|
-
return this.axiosInstance.
|
|
814
|
+
return this.axiosInstance.post(`${this.baseURL}curtain-chunked-upload/${uploadId}/`, formData, { headers: headers });
|
|
811
815
|
}
|
|
812
816
|
cancelCurtainUpload(uploadId) {
|
|
813
817
|
let headers = new AxiosHeaders();
|
|
@@ -819,8 +823,11 @@ export class CurtainWebAPI {
|
|
|
819
823
|
let uploadId;
|
|
820
824
|
let offset = 0;
|
|
821
825
|
const totalSize = file.size;
|
|
826
|
+
const sha256Hasher = new jsSHA('SHA-256', 'ARRAYBUFFER');
|
|
822
827
|
if (totalSize <= chunkSize) {
|
|
823
828
|
try {
|
|
829
|
+
const fileBuffer = await file.arrayBuffer();
|
|
830
|
+
sha256Hasher.update(fileBuffer);
|
|
824
831
|
const response = await this.uploadCurtainChunk({
|
|
825
832
|
file: file,
|
|
826
833
|
filename: file.name,
|
|
@@ -832,7 +839,9 @@ export class CurtainWebAPI {
|
|
|
832
839
|
expiry_duration: options?.expiry_duration,
|
|
833
840
|
enable: options?.enable
|
|
834
841
|
});
|
|
842
|
+
const sha256Hash = sha256Hasher.getHash('HEX');
|
|
835
843
|
const completionResponse = await this.completeCurtainUpload(response.data.id, {
|
|
844
|
+
sha256: sha256Hash,
|
|
836
845
|
name: options?.name,
|
|
837
846
|
description: options?.description,
|
|
838
847
|
curtain_type: options?.curtain_type,
|
|
@@ -854,7 +863,9 @@ export class CurtainWebAPI {
|
|
|
854
863
|
if (offset >= totalSize) {
|
|
855
864
|
if (uploadId) {
|
|
856
865
|
try {
|
|
866
|
+
const sha256Hash = sha256Hasher.getHash('HEX');
|
|
857
867
|
const completionResponse = await this.completeCurtainUpload(uploadId, {
|
|
868
|
+
sha256: sha256Hash,
|
|
858
869
|
name: options?.name,
|
|
859
870
|
description: options?.description,
|
|
860
871
|
curtain_type: options?.curtain_type,
|
|
@@ -879,6 +890,8 @@ export class CurtainWebAPI {
|
|
|
879
890
|
const end = Math.min(offset + chunkSize, totalSize);
|
|
880
891
|
const chunk = file.slice(offset, end);
|
|
881
892
|
try {
|
|
893
|
+
const chunkBuffer = await chunk.arrayBuffer();
|
|
894
|
+
sha256Hasher.update(chunkBuffer);
|
|
882
895
|
const response = await this.uploadCurtainChunk({
|
|
883
896
|
file: chunk,
|
|
884
897
|
filename: file.name,
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {User} from "./curtain-user";
|
|
2
2
|
import axios, {AxiosHeaders} from "axios";
|
|
3
|
+
import jsSHA from "jssha";
|
|
3
4
|
import {
|
|
4
5
|
arrayBufferToBase64String, base64ToArrayBuffer,
|
|
5
6
|
CurtainEncryption,
|
|
@@ -80,6 +81,7 @@ export interface CurtainChunkedUploadResponse {
|
|
|
80
81
|
|
|
81
82
|
export interface CurtainChunkedUploadCompletionRequest {
|
|
82
83
|
md5?: string;
|
|
84
|
+
sha256?: string;
|
|
83
85
|
name?: string;
|
|
84
86
|
description?: string;
|
|
85
87
|
curtain_type?: string;
|
|
@@ -999,16 +1001,16 @@ export class CurtainWebAPI {
|
|
|
999
1001
|
formData.append('curtain_type', request.curtain_type);
|
|
1000
1002
|
}
|
|
1001
1003
|
if (request.permanent !== undefined) {
|
|
1002
|
-
formData.append('permanent', request.permanent
|
|
1004
|
+
formData.append('permanent', request.permanent ? 'True' : 'False');
|
|
1003
1005
|
}
|
|
1004
1006
|
if (request.encrypted !== undefined) {
|
|
1005
|
-
formData.append('encrypted', request.encrypted
|
|
1007
|
+
formData.append('encrypted', request.encrypted ? 'True' : 'False');
|
|
1006
1008
|
}
|
|
1007
1009
|
if (request.expiry_duration !== undefined) {
|
|
1008
1010
|
formData.append('expiry_duration', request.expiry_duration.toString());
|
|
1009
1011
|
}
|
|
1010
1012
|
if (request.enable !== undefined) {
|
|
1011
|
-
formData.append('enable', request.enable
|
|
1013
|
+
formData.append('enable', request.enable ? 'True' : 'False');
|
|
1012
1014
|
}
|
|
1013
1015
|
|
|
1014
1016
|
const url = uploadId
|
|
@@ -1044,6 +1046,9 @@ export class CurtainWebAPI {
|
|
|
1044
1046
|
if (request?.md5) {
|
|
1045
1047
|
formData.append('md5', request.md5);
|
|
1046
1048
|
}
|
|
1049
|
+
if (request?.sha256) {
|
|
1050
|
+
formData.append('sha256', request.sha256);
|
|
1051
|
+
}
|
|
1047
1052
|
if (request?.name) {
|
|
1048
1053
|
formData.append('name', request.name);
|
|
1049
1054
|
}
|
|
@@ -1054,16 +1059,16 @@ export class CurtainWebAPI {
|
|
|
1054
1059
|
formData.append('curtain_type', request.curtain_type);
|
|
1055
1060
|
}
|
|
1056
1061
|
if (request?.permanent !== undefined) {
|
|
1057
|
-
formData.append('permanent', request.permanent
|
|
1062
|
+
formData.append('permanent', request.permanent ? 'True' : 'False');
|
|
1058
1063
|
}
|
|
1059
1064
|
if (request?.encrypted !== undefined) {
|
|
1060
|
-
formData.append('encrypted', request.encrypted
|
|
1065
|
+
formData.append('encrypted', request.encrypted ? 'True' : 'False');
|
|
1061
1066
|
}
|
|
1062
1067
|
if (request?.expiry_duration !== undefined) {
|
|
1063
1068
|
formData.append('expiry_duration', request.expiry_duration.toString());
|
|
1064
1069
|
}
|
|
1065
1070
|
if (request?.enable !== undefined) {
|
|
1066
|
-
formData.append('enable', request.enable
|
|
1071
|
+
formData.append('enable', request.enable ? 'True' : 'False');
|
|
1067
1072
|
}
|
|
1068
1073
|
if (request?.curtain_id !== undefined) {
|
|
1069
1074
|
formData.append('curtain_id', request.curtain_id.toString());
|
|
@@ -1074,7 +1079,7 @@ export class CurtainWebAPI {
|
|
|
1074
1079
|
|
|
1075
1080
|
let headers = new AxiosHeaders();
|
|
1076
1081
|
headers["Accept"] = "application/json";
|
|
1077
|
-
return this.axiosInstance.
|
|
1082
|
+
return this.axiosInstance.post<CurtainChunkedUploadCompletionResponse>(`${this.baseURL}curtain-chunked-upload/${uploadId}/`, formData, {headers: headers});
|
|
1078
1083
|
}
|
|
1079
1084
|
|
|
1080
1085
|
cancelCurtainUpload(uploadId: string) {
|
|
@@ -1104,9 +1109,13 @@ export class CurtainWebAPI {
|
|
|
1104
1109
|
let uploadId: string | undefined;
|
|
1105
1110
|
let offset = 0;
|
|
1106
1111
|
const totalSize = file.size;
|
|
1112
|
+
const sha256Hasher = new jsSHA('SHA-256', 'ARRAYBUFFER');
|
|
1107
1113
|
|
|
1108
1114
|
if (totalSize <= chunkSize) {
|
|
1109
1115
|
try {
|
|
1116
|
+
const fileBuffer = await file.arrayBuffer();
|
|
1117
|
+
sha256Hasher.update(fileBuffer);
|
|
1118
|
+
|
|
1110
1119
|
const response = await this.uploadCurtainChunk({
|
|
1111
1120
|
file: file,
|
|
1112
1121
|
filename: file.name,
|
|
@@ -1119,7 +1128,9 @@ export class CurtainWebAPI {
|
|
|
1119
1128
|
enable: options?.enable
|
|
1120
1129
|
});
|
|
1121
1130
|
|
|
1131
|
+
const sha256Hash = sha256Hasher.getHash('HEX');
|
|
1122
1132
|
const completionResponse = await this.completeCurtainUpload(response.data.id, {
|
|
1133
|
+
sha256: sha256Hash,
|
|
1123
1134
|
name: options?.name,
|
|
1124
1135
|
description: options?.description,
|
|
1125
1136
|
curtain_type: options?.curtain_type,
|
|
@@ -1141,7 +1152,9 @@ export class CurtainWebAPI {
|
|
|
1141
1152
|
if (offset >= totalSize) {
|
|
1142
1153
|
if (uploadId) {
|
|
1143
1154
|
try {
|
|
1155
|
+
const sha256Hash = sha256Hasher.getHash('HEX');
|
|
1144
1156
|
const completionResponse = await this.completeCurtainUpload(uploadId, {
|
|
1157
|
+
sha256: sha256Hash,
|
|
1145
1158
|
name: options?.name,
|
|
1146
1159
|
description: options?.description,
|
|
1147
1160
|
curtain_type: options?.curtain_type,
|
|
@@ -1166,6 +1179,9 @@ export class CurtainWebAPI {
|
|
|
1166
1179
|
const chunk = file.slice(offset, end);
|
|
1167
1180
|
|
|
1168
1181
|
try {
|
|
1182
|
+
const chunkBuffer = await chunk.arrayBuffer();
|
|
1183
|
+
sha256Hasher.update(chunkBuffer);
|
|
1184
|
+
|
|
1169
1185
|
const response = await this.uploadCurtainChunk({
|
|
1170
1186
|
file: chunk,
|
|
1171
1187
|
filename: file.name,
|