Browse Source

Quick.Azure fixes for Tokyo and up

Exilon 5 years ago
parent
commit
10f9044530
1 changed files with 72 additions and 3 deletions
  1. 72 3
      Quick.Azure.pas

+ 72 - 3
Quick.Azure.pas

@@ -5,9 +5,9 @@
   Unit        : Quick.Azure
   Unit        : Quick.Azure
   Description : Azure blobs operations
   Description : Azure blobs operations
   Author      : Kike Pérez
   Author      : Kike Pérez
-  Version     : 1.2
+  Version     : 1.4
   Created     : 27/08/2015
   Created     : 27/08/2015
-  Modified    : 11/03/2019
+  Modified    : 08/10/2019
 
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
 
@@ -29,6 +29,8 @@
 
 
 unit Quick.Azure;
 unit Quick.Azure;
 
 
+{$i QuickLib.inc}
+
 interface
 interface
 
 
 uses
 uses
@@ -38,7 +40,8 @@ uses
   IPPeerClient,
   IPPeerClient,
   IdURI,
   IdURI,
   Data.Cloud.CloudAPI,
   Data.Cloud.CloudAPI,
-  Data.Cloud.AzureAPI;
+  Data.Cloud.AzureAPI,
+  Quick.Commons;
 
 
 type
 type
 
 
@@ -54,6 +57,7 @@ type
   TAzureBlobObject = class
   TAzureBlobObject = class
     Name : string;
     Name : string;
     Size : Int64;
     Size : Int64;
+    IsDir : Boolean;
     LastModified : TDateTime;
     LastModified : TDateTime;
   end;
   end;
 
 
@@ -565,6 +569,70 @@ begin
   end;
   end;
 end;
 end;
 
 
+{$IFDEF DELPHITOKYO_UP}
+function TQuickAzure.ListBlobs(const azContainer, azBlobsStartWith : string; Recursive : Boolean; out azResponseInfo : TAzureResponseInfo) : TBlobList;
+var
+  BlobService : TAzureBlobService;
+  azBlob : TAzureBlobItem;
+  azBlobList : TArray<TAzureBlobItem>;
+  Blob : TAzureBlobObject;
+  CloudResponseInfo : TCloudResponseInfo;
+  cNextMarker : string;
+  container : string;
+  prefix : string;
+  blobprefix : TArray<string>;
+  xmlresp : string;
+  folder : string;
+  prop : TPair<string,string>;
+begin
+  Result := TBlobList.Create(True);
+  cNextMarker := '';
+  container := CheckContainer(azContainer);
+  BlobService := TAzureBlobService.Create(fconAzure);
+  try
+    if Recursive then prefix := ''
+      else prefix := '/';
+    BlobService.Timeout := fTimeout;
+    repeat
+      CloudResponseInfo := TCloudResponseInfo.Create;
+      try
+        azBlobList := BlobService.ListBlobs(azContainer,azBlobsStartWith,'/',cNextMarker,100,[],cNextMarker,blobprefix,xmlresp,CloudResponseInfo);
+        azResponseInfo := GetResponseInfo(CloudResponseInfo);
+        //get folders (prefix)
+        for folder in blobprefix do
+        begin
+          Blob := TAzureBlobObject.Create;
+          if folder.EndsWith('/') then Blob.Name := RemoveLastChar(folder)
+            else Blob.Name := folder;
+          Blob.Name := Copy(Blob.Name,Blob.Name.LastDelimiter('/')+2,Blob.Name.Length);
+          Blob.IsDir := True;
+          Result.Add(Blob);
+        end;
+        //get files (blobs)
+        if Assigned(azBlobList) then
+        begin
+          for azBlob in azBlobList do
+          begin
+            Blob := TAzureBlobObject.Create;
+            Blob.Name := azBlob.Name;
+            for prop in azBlob.Properties do
+            begin
+              if prop.Key = 'Content-Length' then Blob.Size := StrToInt64Def(prop.Value,0)
+                else if prop.Key = 'Last-Modified' then Blob.LastModified := GMT2DateTime(prop.Value);
+            end;
+            Blob.IsDir := False;
+            Result.Add(Blob);
+          end;
+        end;
+      finally
+        CloudResponseInfo.Free;
+      end;
+    until (cNextMarker = '') or (azResponseInfo.StatusCode <> 200);
+  finally
+    BlobService.Free;
+  end;
+end;
+{$ELSE}
 function TQuickAzure.ListBlobs(const azContainer, azBlobsStartWith : string; Recursive : Boolean; out azResponseInfo : TAzureResponseInfo) : TBlobList;
 function TQuickAzure.ListBlobs(const azContainer, azBlobsStartWith : string; Recursive : Boolean; out azResponseInfo : TAzureResponseInfo) : TBlobList;
 var
 var
   BlobService : TAzureBlobService;
   BlobService : TAzureBlobService;
@@ -620,6 +688,7 @@ begin
     BlobService.Free;
     BlobService.Free;
   end;
   end;
 end;
 end;
+{$ENDIF}
 
 
 function TQuickAzure.ListBlobsNames(const azContainer, azBlobsStartWith : string; Recursive : Boolean; out azResponseInfo : TAzureResponseInfo) : TStrings;
 function TQuickAzure.ListBlobsNames(const azContainer, azBlobsStartWith : string; Recursive : Boolean; out azResponseInfo : TAzureResponseInfo) : TStrings;
 var
 var