Skip to content

Commit 0251bcc

Browse files
fix jquery + backend
1 parent 59335aa commit 0251bcc

File tree

6 files changed

+43
-32
lines changed

6 files changed

+43
-32
lines changed

Amazon_Backend/AmazonS3_Backend/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ public static void Main(string[] args) {
3636
BucketName = builder.Configuration.GetValue<string>("AWS:Bucket")!;
3737

3838
awsOptions.Credentials = new BasicAWSCredentials(accessKey, secretKey);
39-
4039
awsOptions.Region = RegionEndpoint.GetBySystemName(region);
4140

42-
4341
builder.Services.AddDefaultAWSOptions(awsOptions);
4442

4543
builder.Services.AddAWSService<IAmazonS3>();

Amazon_Backend/AmazonS3_Backend/Providers/AmazonS3Provider.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public async Task MoveItemAsync(string sourceKey, string destinationKey) {
165165
throw;
166166
}
167167
}
168+
168169
public async Task RenameItemAsync(string key, string? directory, string newName) {
169170
if (IsDirectory(key)) {
170171
throw new NotImplementedException("Renaming directories is not implemented");
@@ -203,6 +204,7 @@ List<FileSystemItem> GetItemsFromS3Objects(List<S3Object> objects) {
203204
}
204205
return result;
205206
}
207+
206208
public string GetDirectoryNameFromKey(string key) {
207209
if (string.IsNullOrEmpty(key))
208210
throw new ArgumentException("Directory name cannot be empty");
@@ -226,20 +228,6 @@ public async Task<List<FileSystemItem>> GetDirectoriesFromCommonPrefixes(List<st
226228
}
227229
return result;
228230
}
229-
public async Task<string> GetPresignedUrl(string key, int expirationSeconds) {
230-
DateTime expiration = DateTime.UtcNow.AddSeconds(expirationSeconds);
231-
232-
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest {
233-
BucketName = BucketName,
234-
//Key = key,
235-
236-
Verb = HttpVerb.PUT,
237-
Expires = expiration,
238-
239-
};
240-
241-
return await Client.GetPreSignedURLAsync(request);
242-
}
243231

244232
public async Task<bool> HasDirectorySubDirectoriesAsync(string key) {
245233
try {
@@ -256,6 +244,7 @@ public async Task<bool> HasDirectorySubDirectoriesAsync(string key) {
256244
throw;
257245
}
258246
}
247+
259248
string GetNewDirectoryName(string? path, string name) {
260249
if (string.IsNullOrWhiteSpace(name))
261250
throw new ArgumentException("Directory name cannot be null or empty");

Amazon_Backend/AmazonS3_Backend/appsettings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
},
88
"AllowedHosts": "*",
99
"AWS": {
10-
"Profile": "default"
10+
"Profile": "default",
11+
"AccessKey": "",
12+
"SecretKey": "",
13+
"Region": "us-east-1",
14+
"Bucket": ""
1115
}
1216
}

jQuery/src/amazon.filesystem.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ class AmazonFileSystem {
4949
try {
5050
return await this.gateway.moveItem(item.key, `${destinationDir.key}${item.name}`);
5151
} catch (error) {
52-
throw new DevExpress.fileManagement.FileSystemError(32767, item.key, error.message);
52+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
53+
}
54+
}
55+
56+
async abortFileUpload(fileData, uploadInfo) {
57+
try {
58+
await this.gateway.abortFileUpload(fileData, uploadInfo);
59+
} catch (error) {
60+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
5361
}
5462
}
5563

jQuery/src/amazon.gateway.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ class AmazonGateway {
3434
async getItems(key) {
3535
const params = { 'path': key };
3636
const requestParams = { method: 'GET' };
37-
return this.makeRequestAsync('getItems', params, requestParams);
37+
return this.makeRequest('getItems', params, requestParams);
3838
}
3939

4040
async renameItem(key, parentPath, name) {
4141
const params = { 'key': key, 'directory': parentPath, 'newName': name };
4242
const requestParams = { method: 'PUT' };
43-
await this.makeRequestAsync('renameItem', params, requestParams);
43+
await this.makeRequest('renameItem', params, requestParams);
4444
}
4545

4646
async createDirectory(key, name) {
4747
const params = { 'path': key, 'name': name };
4848
const requestParams = { method: 'PUT' };
49-
await this.makeRequestAsync('createDirectory', params, requestParams);
49+
await this.makeRequest('createDirectory', params, requestParams);
5050
}
5151

5252
async deleteItem(key) {
@@ -58,19 +58,19 @@ class AmazonGateway {
5858
async copyItem(sourceKey, destinationKey) {
5959
const params = { 'sourceKey': sourceKey, 'destinationKey': destinationKey };
6060
const requestParams = { method: 'PUT' };
61-
await this.makeRequestAsync('copyItem', params, requestParams);
61+
await this.makeRequest('copyItem', params, requestParams);
6262
}
6363

6464
async moveItem(sourceKey, destinationKey) {
6565
const params = { 'sourceKey': sourceKey, 'destinationKey': destinationKey };
6666
const requestParams = { method: 'POST' };
67-
await this.makeRequestAsync('moveItem', params, requestParams);
67+
await this.makeRequest('moveItem', params, requestParams);
6868
}
6969

7070
async downloadItems(keys) {
7171
const params = {};
7272
const requestParams = { method: 'POST', body: JSON.stringify(keys), headers: this.defaultHeaders };
73-
return this.makeRequestAsync('downloadItems', params, requestParams);
73+
return this.makeRequest('downloadItems', params, requestParams);
7474
}
7575

7676
async uploadPart(fileData, uploadInfo, destinationDirectory) {
@@ -89,7 +89,7 @@ class AmazonGateway {
8989
body: data,
9090
};
9191

92-
const etag = await this.makeRequestAsync('uploadPart', params, requestOptions);
92+
const etag = await this.makeRequest('uploadPart', params, requestOptions);
9393
// partNumber must be > 0
9494
this.addPartToUploadData(key, { PartNumber: uploadInfo.chunkIndex + 1, ETag: etag });
9595
}
@@ -106,7 +106,7 @@ class AmazonGateway {
106106
body: JSON.stringify(this.getParts(key)),
107107
};
108108

109-
await this.makeRequestAsync('completeUpload', params, requestOptions);
109+
await this.makeRequest('completeUpload', params, requestOptions);
110110
this.removeUploadData(key);
111111
}
112112

@@ -117,21 +117,30 @@ class AmazonGateway {
117117
headers: this.defaultHeaders,
118118
};
119119

120-
const uploadId = await this.makeRequestAsync('initUpload', params, requestOptions);
120+
const uploadId = await this.makeRequest('initUpload', params, requestOptions);
121121
this.initUploadData(params.key, uploadId);
122122
}
123123

124+
async abortFileUpload(fileData, uploadInfo, destinationDirectory) {
125+
const params = { uploadId: this.getUploadId(fileData.name) };
126+
const requestOptions = {
127+
method: 'POST',
128+
headers: this.defaultHeaders
129+
};
130+
return this.makeRequest('abortUpload', params, requestOptions);
131+
}
132+
124133
/* eslint-disable-next-line spellcheck/spell-checker */
125134
async getPresignedDownloadUrl(fileName) {
126135
const params = { key: fileName };
127136
const requestOptions = {
128137
method: 'POST',
129138
headers: this.defaultHeaders,
130139
};
131-
return this.makeRequestAsync('getPresignedDownloadUrl', params, requestOptions);
140+
return this.makeRequest('getPresignedDownloadUrl', params, requestOptions);
132141
}
133142

134-
async makeRequestAsync(method, queryParams, requestParams) {
143+
async makeRequest(method, queryParams, requestParams) {
135144
const requestUrl = this.getRequestUrl(method);
136145
const url = new URL(requestUrl);
137146

jQuery/src/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ $(() => {
1111
moveItem,
1212
uploadFileChunk,
1313
downloadItems,
14+
abortFileUpload,
1415
});
1516

1617
$('#file-manager').dxFileManager({
1718
fileSystemProvider: provider,
1819

1920
allowedFileExtensions: [],
2021
upload: {
21-
// maxFileSize: 1048576,
22-
chunkSize: 6000000,
22+
chunkSize: 5242880,
2323
},
2424
permissions: {
2525
download: true,
26-
// uncomment the code below to enable file/directory management
2726
create: true,
2827
copy: true,
2928
move: true,
@@ -58,6 +57,10 @@ function moveItem(item, destinationDirectory) {
5857
return amazon.moveItem(item, destinationDirectory);
5958
}
6059

60+
async function abortFileUpload(fileData, uploadInfo) {
61+
return amazon.abortFileUpload(fileData, uploadInfo);
62+
}
63+
6164
async function uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
6265
await amazon.uploadFileChunk(fileData, uploadInfo, destinationDirectory);
6366
}

0 commit comments

Comments
 (0)