From b2242caabd575b9d3566e41327bdc49ded990acf Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Tue, 14 Nov 2017 23:04:57 +0100 Subject: [PATCH] Start of lists support --- res/static/res/script/listmaker.js | 38 +++++++---- res/template/fragments/api/list-post.html | 83 +++++++++++++++-------- res/template/home.html | 4 +- 3 files changed, 81 insertions(+), 44 deletions(-) diff --git a/res/static/res/script/listmaker.js b/res/static/res/script/listmaker.js index c7f53ff..6a08a59 100644 --- a/res/static/res/script/listmaker.js +++ b/res/static/res/script/listmaker.js @@ -1,6 +1,10 @@ var listItems = new Array(); +$("#btnCreateList").click(function (evt) { + createList(); +}); + function addToList(id, desc){ var listEntry = {id: id, desc: desc}; @@ -8,7 +12,7 @@ function addToList(id, desc){ } function createList(){ - var url = "/api/createlist/"; + var url = "/api/list"; var postData = {}; @@ -20,17 +24,29 @@ function createList(){ if(title === null){ return; } - - postData["title" ] = title; + + var postData = { + "title": title, + "description": "yo", + "files": new Array() + }; var arrayLength = listItems.length; for (var i = 0; i < arrayLength; i++) { - postData["id" + i] = listItems[i]["id"]; - postData["desc" + i] = listItems[i]["desc"]; + postData.files[i] = { + "id": listItems[i]["id"], + "description": listItems[i]["desc"] + }; } - $.post(url, postData, function(response){ - listCreated(response); + $.ajax({ + url: url, + contentType: "application/json", + method: "POST", + data: JSON.stringify(postData), + dataType: "json", + success: listCreated, + error: listCreated }); } @@ -38,7 +54,7 @@ function listCreated(response){ if(response.status === "success"){ resultString = "
List creation finished!
" + "Your List URL:
" - + "" + response.url + "" + + "/l/" + response.id + "" + "
"; $('#uploads-container').prepend( @@ -66,8 +82,4 @@ function listCreated(response){ // // $("#txtListId").val(""); // $("#txtListDesc").val(""); -//}); - -$("#btnListCreate").click(function (evt) { - createList(); -}); \ No newline at end of file +//}); \ No newline at end of file diff --git a/res/template/fragments/api/list-post.html b/res/template/fragments/api/list-post.html index 09e8a5f..150d176 100644 --- a/res/template/fragments/api/list-post.html +++ b/res/template/fragments/api/list-post.html @@ -1,5 +1,5 @@ {{define "api-list-post"}} -
+
POST: /list

Description

@@ -8,45 +8,70 @@ viewer page.

Parameters

- - - - - - - - - - - - - -
ParamRequiredLocationDescription
idtrueURLID of the file to delete
+

+ POST body should be a JSON object, example below. A list can contain + maximally 5000 files. If you try to add more the request will fail. +

+

Example

+
+{
+	"title": "My beautiful photos",
+	"description": "An album of photos from my vacation in Austria",
+	"files": [ // Ordered array of files to add to the list
+		{
+			"id": "abc123",
+			"description": "First photo of the week, such a beautiful valley"
+		},
+		{
+			"id": "123abc",
+			"description": "The week went by so quickly, here's a photo from the plane back"
+		}
+	]
+}
+

Returns

HTTP 200: OK
 {
 	"success": true,
-	"value": "file_deleted",
-	"message": "The file has been deleted."
-}
-
HTTP 404: Not Found
+	"id": "yay137" // ID of the newly created list
+}
+
+
HTTP 422: Unprocessable Entity
 {
 	"success": false,
 	"value": "file_not_found",
-	"message": "File ID was not found in the database."
-}
-
HTTP 401: Unauthorized
+	"id": "Oh42No", // The file you tried to add with this ID does not exist
+	"message": "File Oh42No was not found in the database."
+}
+
+
HTTP 413: Payload too large
 {
 	"success": false,
-	"value": "unauthorized",
-	"message": "You are not logged in."
-}
-
HTTP 403: Forbidden
+	"value": "too_many_files",
+	"message": "This list contains too many files, max 5000 allowed."
+}
+
+
HTTP 422: Unprocessable Entity
 {
 	"success": false,
-	"value": "forbidden",
-	"message": "This is not your file."
-}
+ "value": "json_parse_failed", + "message": "The JSON object in the request body could not be read." +} + +
HTTP 413: Payload too large
+{
+	"success": false,
+	"value": "title_too_long",
+	"message": "The title of this list is too long, max 300 characters allowed."
+}
+
+
HTTP 413: Payload too large
+{
+	"success": false,
+	"value": "description_too_long",
+	"message": "The description of this list or one of the files in the list is too long, max 3000 characters allowed."
+}
+
{{end}} \ No newline at end of file diff --git a/res/template/home.html b/res/template/home.html index 8aa4b30..2e69bca 100644 --- a/res/template/home.html +++ b/res/template/home.html @@ -51,7 +51,7 @@

Pixeldrain Public Beta

@@ -145,7 +145,7 @@ - + {{template "analytics"}}