curtain-web-api 1.0.83 → 1.0.85

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.
@@ -47,6 +47,7 @@ export interface CurtainChunkedUploadResponse {
47
47
  }
48
48
  export interface CurtainChunkedUploadCompletionRequest {
49
49
  md5?: string;
50
+ sha256?: string;
50
51
  name?: string;
51
52
  description?: string;
52
53
  curtain_type?: string;
@@ -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.toString());
744
+ formData.append('permanent', request.permanent ? 'True' : 'False');
744
745
  }
745
746
  if (request.encrypted !== undefined) {
746
- formData.append('encrypted', request.encrypted.toString());
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.toString());
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.toString());
795
+ formData.append('permanent', request.permanent ? 'True' : 'False');
792
796
  }
793
797
  if (request?.encrypted !== undefined) {
794
- formData.append('encrypted', request.encrypted.toString());
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.toString());
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());
@@ -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,
@@ -878,9 +889,12 @@ export class CurtainWebAPI {
878
889
  }
879
890
  const end = Math.min(offset + chunkSize, totalSize);
880
891
  const chunk = file.slice(offset, end);
892
+ const chunkFile = new File([chunk], file.name, { type: file.type });
881
893
  try {
894
+ const chunkBuffer = await chunk.arrayBuffer();
895
+ sha256Hasher.update(chunkBuffer);
882
896
  const response = await this.uploadCurtainChunk({
883
- file: chunk,
897
+ file: chunkFile,
884
898
  filename: file.name,
885
899
  upload_session_id: options?.upload_session_id,
886
900
  description: options?.description,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "curtain-web-api",
3
- "version": "1.0.83",
3
+ "version": "1.0.85",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",
@@ -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.toString());
1004
+ formData.append('permanent', request.permanent ? 'True' : 'False');
1003
1005
  }
1004
1006
  if (request.encrypted !== undefined) {
1005
- formData.append('encrypted', request.encrypted.toString());
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.toString());
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.toString());
1062
+ formData.append('permanent', request.permanent ? 'True' : 'False');
1058
1063
  }
1059
1064
  if (request?.encrypted !== undefined) {
1060
- formData.append('encrypted', request.encrypted.toString());
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.toString());
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());
@@ -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,
@@ -1164,10 +1177,14 @@ export class CurtainWebAPI {
1164
1177
 
1165
1178
  const end = Math.min(offset + chunkSize, totalSize);
1166
1179
  const chunk = file.slice(offset, end);
1180
+ const chunkFile = new File([chunk], file.name, { type: file.type });
1167
1181
 
1168
1182
  try {
1183
+ const chunkBuffer = await chunk.arrayBuffer();
1184
+ sha256Hasher.update(chunkBuffer);
1185
+
1169
1186
  const response = await this.uploadCurtainChunk({
1170
- file: chunk,
1187
+ file: chunkFile,
1171
1188
  filename: file.name,
1172
1189
  upload_session_id: options?.upload_session_id,
1173
1190
  description: options?.description,