Files
fnx_web/res/template/history.html
2022-06-07 14:43:01 +02:00

116 lines
3.2 KiB
HTML

{{define "history_cookies"}}<!DOCTYPE html>
<html lang="en">
<head>
{{template "meta_tags" "Upload History"}}
</head>
<body>
{{template "page_top" .}}
<header>
<h1>Upload History</h1>
</header>
<section>
<p>
Here are all files you have previously uploaded to pixeldrain using this computer.
This data is saved locally in your web browser and gets updated every time you upload a file through your current browser.
</p>
</section>
<div id="uploaded_files"></div>
{{template "page_bottom" .}}
<script>
let apiEndpoint = '{{.APIEndpoint}}';
function renderFileButton(apiURL, id, title, subtitle) {
let btn = document.createElement("a")
btn.classList = "file_button"
btn.href = "/u/" + id
btn.target = "_blank"
let thumbnail = document.createElement("img")
thumbnail.src = apiURL + "/file/" + id + "/thumbnail?width=80&height=80"
thumbnail.alt = title
let titleSpan = document.createElement("span")
titleSpan.classList = "file_button_title"
titleSpan.innerText = title
let br = document.createElement("br")
let subtitleSpan = document.createElement("span")
subtitleSpan.classList = "file_button_subtitle"
subtitleSpan.innerText = subtitle
btn.appendChild(thumbnail)
btn.appendChild(titleSpan)
btn.appendChild(br)
btn.appendChild(subtitleSpan)
return btn
}
function getCookie(name) {
var result = new RegExp('(?:^|; )' + encodeURIComponent(name) + '=([^;]*)').exec(document.cookie)
return result ? result[1] : null
}
function printDate(date, hours, minutes, seconds) {
let dateStr = date.getFullYear()
+ "-" + ("00" + (date.getMonth() + 1)).slice(-2)
+ "-" + ("00" + date.getDate()).slice(-2)
if (hours) { dateStr += " " + ("00" + date.getHours()).slice(-2) }
if (minutes) { dateStr += ":" + ("00" + date.getMinutes()).slice(-2) }
if (seconds) { dateStr += ":" + ("00" + date.getMinutes()).slice(-2) }
return dateStr
}
// Get the uploads from localstorage
let uploadsStr = localStorage.getItem("uploaded_files")
if (uploadsStr === null) { uploadsStr = "" }
let uploads = Array()
if (uploadsStr != "") {
// Strip the trailing comma
uploads = uploadsStr.slice(0, -1).split(",")
}
// Get the uploads from a cookie
uploadsStr = getCookie("pduploads")
if (uploadsStr === null) { uploadsStr = "" }
if (uploadsStr != "") {
uploadsStr = uploadsStr.slice(0, -1) // Strip the trailing dot
uploads.push(uploadsStr.split(".").reverse())
}
// Render all the items
function getHistoryItem() {
let item = uploads.shift()
if (item === undefined || item === "") { return }
fetch(
apiEndpoint + "/file/" + item + "/info"
).then(resp => {
if (!resp.ok) {
return Promise.reject()
}
return resp.json()
}).then(resp => {
document.getElementById("uploaded_files").appendChild(
renderFileButton(
apiEndpoint,
resp.id,
resp.name,
printDate(new Date(resp.date_upload), true, true, true),
)
)
getHistoryItem()
}).catch(err => {
console.log("Fetch failed: " + err)
getHistoryItem()
})
}
getHistoryItem()
</script>
{{template "analytics"}}
</body>
</html>{{end}}