Start of lists support

This commit is contained in:
2017-11-14 23:04:57 +01:00
parent 104e9aa835
commit b2242caabd
3 changed files with 81 additions and 44 deletions

View File

@@ -1,6 +1,10 @@
var listItems = new Array(); var listItems = new Array();
$("#btnCreateList").click(function (evt) {
createList();
});
function addToList(id, desc){ function addToList(id, desc){
var listEntry = {id: id, desc: desc}; var listEntry = {id: id, desc: desc};
@@ -8,7 +12,7 @@ function addToList(id, desc){
} }
function createList(){ function createList(){
var url = "/api/createlist/"; var url = "/api/list";
var postData = {}; var postData = {};
@@ -20,17 +24,29 @@ function createList(){
if(title === null){ if(title === null){
return; return;
} }
postData["title" ] = title; var postData = {
"title": title,
"description": "yo",
"files": new Array()
};
var arrayLength = listItems.length; var arrayLength = listItems.length;
for (var i = 0; i < arrayLength; i++) { for (var i = 0; i < arrayLength; i++) {
postData["id" + i] = listItems[i]["id"]; postData.files[i] = {
postData["desc" + i] = listItems[i]["desc"]; "id": listItems[i]["id"],
"description": listItems[i]["desc"]
};
} }
$.post(url, postData, function(response){ $.ajax({
listCreated(response); 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"){ if(response.status === "success"){
resultString = "<div class=\"uploadHistory\">List creation finished!<br/>" resultString = "<div class=\"uploadHistory\">List creation finished!<br/>"
+ "Your List URL: <br/>" + "Your List URL: <br/>"
+ "<a href=\"" + response.url + "\" target=\"_blank\" style=\"font-weight: bold;\">" + response.url + "</a>" + "<a href=\"/l/" + response.id + "\" target=\"_blank\" style=\"font-weight: bold;\">/l/" + response.id + "</a>"
+ "</div>"; + "</div>";
$('#uploads-container').prepend( $('#uploads-container').prepend(
@@ -66,8 +82,4 @@ function listCreated(response){
// //
// $("#txtListId").val(""); // $("#txtListId").val("");
// $("#txtListDesc").val(""); // $("#txtListDesc").val("");
//}); //});
$("#btnListCreate").click(function (evt) {
createList();
});

View File

@@ -1,5 +1,5 @@
{{define "api-list-post"}} {{define "api-list-post"}}
<details th:fragment="details" class="api_doc_details request_post"> <details class="api_doc_details request_post">
<summary>POST: /list</summary> <summary>POST: /list</summary>
<div> <div>
<h3>Description</h3> <h3>Description</h3>
@@ -8,45 +8,70 @@
viewer page. viewer page.
</p> </p>
<h3>Parameters</h3> <h3>Parameters</h3>
<table> <p>
<tr> POST body should be a JSON object, example below. A list can contain
<td>Param</td> maximally 5000 files. If you try to add more the request will fail.
<td>Required</td> </p>
<td>Location</td> <h4>Example</h4>
<td>Description</td> <pre>
</tr> {
<tr> "title": "My beautiful photos",
<td>id</td> "description": "An album of photos from my vacation in Austria",
<td>true</td> "files": [ // Ordered array of files to add to the list
<td>URL</td> {
<td>ID of the file to delete</td> "id": "abc123",
</tr> "description": "First photo of the week, such a beautiful valley"
</table> },
{
"id": "123abc",
"description": "The week went by so quickly, here's a photo from the plane back"
}
]
}
</pre>
<h3>Returns</h3> <h3>Returns</h3>
<pre>HTTP 200: OK <pre>HTTP 200: OK
{ {
"success": true, "success": true,
"value": "file_deleted", "id": "yay137" // ID of the newly created list
"message": "The file has been deleted." }
}</pre> </pre>
<pre>HTTP 404: Not Found <pre>HTTP 422: Unprocessable Entity
{ {
"success": false, "success": false,
"value": "file_not_found", "value": "file_not_found",
"message": "File ID was not found in the database." "id": "Oh42No", // The file you tried to add with this ID does not exist
}</pre> "message": "File Oh42No was not found in the database."
<pre>HTTP 401: Unauthorized }
</pre>
<pre>HTTP 413: Payload too large
{ {
"success": false, "success": false,
"value": "unauthorized", "value": "too_many_files",
"message": "You are not logged in." "message": "This list contains too many files, max 5000 allowed."
}</pre> }
<pre>HTTP 403: Forbidden </pre>
<pre>HTTP 422: Unprocessable Entity
{ {
"success": false, "success": false,
"value": "forbidden", "value": "json_parse_failed",
"message": "This is not your file." "message": "The JSON object in the request body could not be read."
}</pre> }
</pre>
<pre>HTTP 413: Payload too large
{
"success": false,
"value": "title_too_long",
"message": "The title of this list is too long, max 300 characters allowed."
}
</pre>
<pre>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."
}
</pre>
</div> </div>
</details> </details>
{{end}} {{end}}

View File

@@ -51,7 +51,7 @@
<div id="uploads-completed"></div> <div id="uploads-completed"></div>
</div> </div>
<div class="highlight bg-dark border-bottom"> <div class="highlight bg-dark border-bottom">
<a id="btnOpenAsList" href="#">Open uploaded files as list</a> <a id="btnCreateList" href="#">Create list with uploaded files</a>
</div> </div>
<h1>Pixeldrain Public Beta<img src="/res/img/sia.png" style="height: 40px;"/></h1> <h1>Pixeldrain Public Beta<img src="/res/img/sia.png" style="height: 40px;"/></h1>
@@ -145,7 +145,7 @@
<script type="text/javascript">var API_URL = "/api";</script> <script type="text/javascript">var API_URL = "/api";</script>
<script src="/res/script/Cookie.js"></script> <script src="/res/script/Cookie.js"></script>
<script src="/res/script/home.js"></script> <script src="/res/script/home.js"></script>
<script src="/res/script/openlist.js"></script> <script src="/res/script/listmaker.js"></script>
{{template "analytics"}} {{template "analytics"}}
</body> </body>
</html> </html>