Skip to content

Commit

Permalink
Fixes #224 and #248. Fixed listing of objects in a bucket and last mo…
Browse files Browse the repository at this point in the history
…dified time. (#251)

* Fixes #224. Fixed listing of objects in a bucket and last modified time.

* Fixed incorrect method toLower() to toLowercase()
  • Loading branch information
anvithks authored and wisererik committed Dec 18, 2019
1 parent 29bdc92 commit 59a1fdf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
<p-column field="size" header="Size" [style]="{'width': '120px'}"></p-column>
<p-column field="Location" header="Location" [style]="{'width': '120px'}" ></p-column>
<p-column field="Tier" header="Tier" ></p-column>
<p-column field="lastModified" header="Last Modified"></p-column>
<p-column field="lastModified" header="Last Modified">
<ng-template pTemplate="body" let-obj="rowData" let-i="rowIndex">
{{obj.lastModified ? (obj.lastModified | date:'long') : '--'}}
</ng-template>
</p-column>
<p-column header="{{I18N.keyID['sds_block_volume_operation']}}" [style]="{'width': '180px'}">
<ng-template pTemplate="body" let-file="rowData" let-i="rowIndex">
<a (click)="downloadFile(file)" *ngIf="!file.newFolder">Download</a>
Expand Down
76 changes: 38 additions & 38 deletions src/app/business/block/bucket-detail/bucket-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class BucketDetailComponent implements OnInit {
}
//Click on folder
folderLink(file){
let folderKey = file.Contents.Key;
let folderKey = file.Key;
if(this.folderId == ""){
this.folderId = folderKey;
}else{
Expand Down Expand Up @@ -218,7 +218,7 @@ export class BucketDetailComponent implements OnInit {
let str = res._body;
let x2js = new X2JS();
let jsonObj = x2js.xml_str2json(str);
let alldir = jsonObj.ListBucketResult ? jsonObj.ListBucketResult :[] ;
let alldir = jsonObj.ListBucketResult.Contents ? jsonObj.ListBucketResult.Contents :[] ;
if(Object.prototype.toString.call(alldir) === "[object Array]"){
this.allDir = alldir;
}else if(Object.prototype.toString.call(alldir) === "[object Object]"){
Expand All @@ -234,17 +234,17 @@ export class BucketDetailComponent implements OnInit {
}
this.allDir = this.allDir.filter(arr=>{
let folderContain = false;
if(arr.Contents.Key.substring(0,this.folderId.length) == this.folderId && arr.Contents.Key.length > this.folderId.length){
if(arr.Key.substring(0,this.folderId.length) == this.folderId && arr.Key.length > this.folderId.length){
// The number of occurrences of ":" in the folder
let folderNum = (this.folderId.split(this.colon)).length-1;
let ObjectKeyNum = (arr.Contents.Key.split(this.colon)).length-1;
let ObjectKeyNum = (arr.Key.split(this.colon)).length-1;
if(folderNum == ObjectKeyNum){
//Identify the file in the folder
folderContain = true;
}else if(ObjectKeyNum == folderNum + 1){
//Identify folders within folders
let lastNum = arr.Contents.Key.lastIndexOf(this.colon);
if(lastNum == arr.Contents.Key.length -1){
let lastNum = arr.Key.lastIndexOf(this.colon);
if(lastNum == arr.Key.length -1){
folderContain = true;
}
}
Expand All @@ -258,48 +258,48 @@ export class BucketDetailComponent implements OnInit {
//Distinguish between folders and files at the first level
this.allDir = this.allDir.filter(item=>{
let folderIndex = false;
if(item.Contents.Key.indexOf(this.colon) !=-1){
if(item.Key.indexOf(this.colon) !=-1){
let index;
index = item.Contents.Key.indexOf(this.colon,index);
index = item.Key.indexOf(this.colon,index);
//Distinguish between folders and files in folders
if(index == item.Contents.Key.length-1){
if(index == item.Key.length-1){
folderIndex = true;
}
}
return item.Contents.Key.indexOf(this.colon) ==-1 || folderIndex;
return item.Key.indexOf(this.colon) ==-1 || folderIndex;
})
}
let folderArray = [];
this.allFolderNameForCheck = [];
this.allDir.forEach(item=>{
item.size = Utils.getDisplayCapacity(item.Contents.Size,2,'KB');
item.lastModified = Utils.formatDate(item.Contents.LastModified *1000);
item.Location = item.Contents.Location;
item.Tier = "Tier_" + item.Contents.Tier + " (" + item.Contents.StorageClass + ")";
if(item.Contents.Key.indexOf(this.colon) !=-1){
item.objectName = item.Contents.Key.slice(0,item.Contents.Key.lastIndexOf(this.colon));
item.size = Utils.getDisplayCapacity(item.Size,2,'KB');
item.lastModified = new Date(item.LastModified).toUTCString();
item.Location = item.Location;
item.Tier = "Tier_" + item.Tier + " (" + item.StorageClass + ")";
if(item.Key.indexOf(this.colon) !=-1){
item.objectName = item.Key.slice(0,item.Key.lastIndexOf(this.colon));
this.allFolderNameForCheck.push(item.objectName);
item.newFolder = true;
item.disabled = false;
item.size = "--";
backupAllDir.forEach(arr=>{
if(this.folderId !=""){
let hasFolder = arr.Contents.Key.indexOf(this.folderId) !=-1 && arr.Contents.Key != this.folderId;
let hasFolder = arr.Key.indexOf(this.folderId) !=-1 && arr.Key != this.folderId;
if( hasFolder){
let newArrKey = arr.Contents.Key.slice(this.folderId.length);
if(newArrKey.slice(0,item.Contents.Key.length) == item.Contents.Key && newArrKey != item.Contents.Key){
let newArrKey = arr.Key.slice(this.folderId.length);
if(newArrKey.slice(0,item.Key.length) == item.Key && newArrKey != item.Key){
item.disabled = true
}
}
}else{
let hasFile = arr.Contents.Key.indexOf(item.Contents.Key) !=-1 && arr.Contents.Key != item.Contents.Key;
if(hasFile && arr.Contents.Key.slice(0,item.Contents.Key.length) == item.Contents.Key){
let hasFile = arr.Key.indexOf(item.Key) !=-1 && arr.Key != item.Key;
if(hasFile && arr.Key.slice(0,item.Key.length) == item.Key){
item.disabled = true
}
}
})
}else{
item.objectName = item.Contents.Key;
item.objectName = item.Key;
item.newFolder = false;
item.disabled = false;
}
Expand All @@ -312,20 +312,20 @@ export class BucketDetailComponent implements OnInit {
resolveObject(){
let set = new Set();
this.allDir.forEach((item,index)=>{
let includeIndex = item.Contents.Key.indexOf(this.colon);
if(includeIndex != -1 && includeIndex < item.Contents.Key.length-1){
let includeIndex = item.Key.indexOf(this.colon);
if(includeIndex != -1 && includeIndex < item.Key.length-1){
while(includeIndex > -1){
set.add(item.Contents.Key.substr(0,includeIndex+1));
includeIndex = item.Contents.Key.indexOf(this.colon, includeIndex+1);
set.add(item.Key.substr(0,includeIndex+1));
includeIndex = item.Key.indexOf(this.colon, includeIndex+1);
}
}
})
this.allDir.forEach(it=>{
set.delete(it.Contents.Key);
set.delete(it.Key);
})
set.forEach(item=>{
let defaultObject = lodash.cloneDeep(this.allDir[0]);
defaultObject.Contents.Key = item;
defaultObject.Key = item;
this.allDir.push(defaultObject);
})
}
Expand Down Expand Up @@ -437,9 +437,9 @@ export class BucketDetailComponent implements OnInit {
downloadFile(file) {
let fileObjectKey;
if(this.folderId !=""){
fileObjectKey = this.folderId + file.Contents.Key;
fileObjectKey = this.folderId + file.Key;
}else{
fileObjectKey = file.Contents.Key;
fileObjectKey = file.Key;
}
let downloadUrl = `${this.BucketService.url}/${this.bucketId}/${fileObjectKey}`;
window['getAkSkList'](()=>{
Expand All @@ -458,14 +458,14 @@ export class BucketDetailComponent implements OnInit {
this.httpClient.get(downloadUrl, options).subscribe((res)=>{
let blob = new Blob([res]);
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(blob, file.Contents.Key);
window.navigator.msSaveBlob(blob, file.Key);
} else {
let URL = window.URL
let objectUrl = URL.createObjectURL(blob)
if (file.Contents.Key) {
if (file.Key) {
let a = document.createElement('a')
a.href = objectUrl
a.download = file.Contents.Key
a.download = file.Key
document.body.appendChild(a)
a.click()
a.remove()
Expand Down Expand Up @@ -524,10 +524,10 @@ export class BucketDetailComponent implements OnInit {
}
deleteFile(file){
let fileObjectKey;
if(file.Contents.Key.indexOf(this.colon) !=-1){
fileObjectKey = file.Contents.Key.slice(0,file.Contents.Key.length-1);
if(file.Key.indexOf(this.colon) !=-1){
fileObjectKey = file.Key.slice(0,file.Key.length-1);
}else{
fileObjectKey = file.Contents.Key;
fileObjectKey = file.Key;
}
let msg = "<div>Are you sure you want to delete the File ?</div><h3>[ "+ fileObjectKey +" ]</h3>";
let header ="Delete";
Expand All @@ -546,7 +546,7 @@ export class BucketDetailComponent implements OnInit {
try {
switch(func){
case "delete":
let objectKey = file.Contents.Key;
let objectKey = file.Key;
//If you want to delete files from a folder, you must include the name of the folder
if(this.folderId !=""){
objectKey = this.folderId + objectKey;
Expand All @@ -566,7 +566,7 @@ export class BucketDetailComponent implements OnInit {
break;
case "deleteMilti":
file.forEach(element => {
let objectKey = element.Contents.Key;
let objectKey = element.Key;
//If you want to delete files from a folder, you must include the name of the folder
if(this.folderId !=""){
objectKey = this.folderId + objectKey;
Expand Down
4 changes: 2 additions & 2 deletions src/app/business/block/buckets.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export class BucketsComponent implements OnInit{
label:item.name,
value:item.name
});
item.encryptionEnabled = item.SSEConfiguration.SSE.enabled.toLower() == "true" ? true : false;
item.versionEnabled = item.VersioningConfiguration.Status.toLower() == "enabled" ? true : false;
item.encryptionEnabled = item.SSEConfiguration.SSE.enabled.toLowerCase() == "true" ? true : false;
item.versionEnabled = item.VersioningConfiguration.Status.toLowerCase() == "enabled" ? true : false;
});
this.initBucket2backendAnd2Type();
});
Expand Down

0 comments on commit 59a1fdf

Please sign in to comment.