瀏覽代碼

Handle s3 bucket with more than 1000 items

luboslenco 3 年之前
父節點
當前提交
30f304a129
共有 1 個文件被更改,包括 16 次插入6 次删除
  1. 16 6
      Sources/arm/sys/File.hx

+ 16 - 6
Sources/arm/sys/File.hx

@@ -135,10 +135,8 @@ class File {
 		}, cloudSizes.get(path));
 	}
 
-	static function initCloud(done: Void->Void) {
-		cloud = [];
-		cloudSizes = [];
-		File.downloadBytes(Config.raw.server, function(bytes: Bytes) {
+	static function initCloudBytes(done: Void->Void, append = "") {
+		File.downloadBytes(Config.raw.server + "/?list-type=2" + append, function(bytes: Bytes) {
 			if (bytes == null) {
 				cloud.set("cloud", []);
 				Console.error(Strings.error5());
@@ -146,7 +144,8 @@ class File {
 			}
 			var files: Array<String> = [];
 			var sizes: Array<Int> = [];
-			for (e in Xml.parse(bytes.toString()).firstElement().elementsNamed("Contents")) {
+			var xml = Xml.parse(bytes.toString());
+			for (e in xml.firstElement().elementsNamed("Contents")) {
 				for (k in e.elementsNamed("Key")) {
 					files.push(k.firstChild().nodeValue);
 				}
@@ -172,7 +171,18 @@ class File {
 					}
 				}
 			}
-			done();
+
+			var isTruncated = xml.firstElement().elementsNamed("IsTruncated").next().firstChild().nodeValue == "true";
+			if (isTruncated) {
+				initCloudBytes(done, "&start-after=" + xml.firstElement().elementsNamed("NextContinuationToken").next().firstChild().nodeValue);
+			}
+			else done();
 		});
 	}
+
+	static function initCloud(done: Void->Void) {
+		cloud = [];
+		cloudSizes = [];
+		initCloudBytes(done);
+	}
 }