+ Upload form hooks for simple uploads

There is still more work to be done for
stabilization as well as updates for more
code quality as right now things are very
ad-hoc.
This commit is contained in:
shockrah 2022-03-24 19:58:20 -07:00
parent d56bd6b7cd
commit 63ac49de5f
2 changed files with 27 additions and 5 deletions

View File

@ -2,6 +2,7 @@
// from their clippable instance. There are no fancy tricks as this is meant
// purely to be a UX thing.
let UID: null|string = null
let KEY: null|string = null
@ -10,6 +11,9 @@ let KEY: null|string = null
* rather than the query string
*/
function setHeaders(xhr: XMLHttpRequest, uid?: string, key?: string) {
UID = (uid) ? uid : UID
KEY = (key) ? key : KEY
xhr.setRequestHeader('ADMIN-API-UID', uid ? uid : UID)
xhr.setRequestHeader('ADMIN-API-KEY', key ? key : KEY)
}
@ -44,8 +48,27 @@ function confirm_auth() {
xhr.send()
}
function upload_video() {
const video_file = document.getElementById('video-file') as HTMLInputElement
const filename = video_file.files[0].name
const category_el = document.getElementById('category') as HTMLInputElement
const cat = category_el.value
function populate_meta_form() {
let xhr = new XMLHttpRequest()
xhr.onload = function() {
if(ok_response(this)) {
video_file.value = ''
document.getElementById('video-meta').hidden = true
document.getElementById('upload-response').textContent = `${filename} uploaded`
}
// TODO Error hanlding
}
xhr.open('post', window.location.origin + `/admin/upload-video/${cat}/${filename}`)
setHeaders(xhr)
xhr.send(video_file.files[0])
}
export function populate_meta_form() {
let file = document.getElementById('video-file') as HTMLInputElement
// When we remove the file this array becomes 0 so the check is required
@ -63,9 +86,8 @@ function populate_meta_form() {
}
}
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('video-file').onchange = populate_meta_form
//document.getElementById('upload-video').onclick = upload_video
document.getElementById('verify-login-btn').onclick = confirm_auth
document.getElementById('confirm-upload-btn').onclick = upload_video
})

View File

@ -28,6 +28,6 @@ document.addEventListener('readystatechange', (e?: Event) : Event => {
switch (get_page_type(document.location.pathname)) {
case PageType.Index: return ready.index_ready_handler(e)
case PageType.Category: return ready.category_ready_handler(e)
case PageType.Admin: return e
case PageType.Admin: return ready.admin_ready_handler(e)
}
})