- When you delete a file it cannot be recovered.
- Nobody will be able to download it and the link will
- stop working. The file will also disappear from any
- lists it's contained in.
-
-
-
-
+ {#if list.can_edit}
+
Edit album
+
Rename
+
+
Delete
+
+ When you delete an album the files in the album will not be deleted,
+ only the album itself.
+
+
+
+
+ {/if}
+
+ {#if file.can_edit}
+
Edit file
+
Rename
+
+
Delete
+
+ When you delete a file it cannot be recovered.
+ Nobody will be able to download it and the link will
+ stop working. The file will also disappear from any
+ lists it's contained in.
+
+
+
+
+ {/if}
diff --git a/svelte/src/file_viewer/FileViewer.svelte b/svelte/src/file_viewer/FileViewer.svelte
index e0d7c5d..5358df5 100644
--- a/svelte/src/file_viewer/FileViewer.svelte
+++ b/svelte/src/file_viewer/FileViewer.svelte
@@ -15,46 +15,60 @@ import AdHead from "./AdHead.svelte";
import AdLeaderboard from "./AdLeaderboard.svelte";
import AdSkyscraper from "./AdSkyscraper.svelte";
import Sharebar from "./Sharebar.svelte";
+import GalleryView from "./GalleryView.svelte";
+import Spinner from "../util/Spinner.svelte";
-let is_list = false
-let embedded = false
-let view_token = ""
-let current_file = {
+const file_struct = {
id: "",
- name: "loading...",
+ name: "",
size: 0,
bandwidth_used: 0,
+ bandwidth_used_paid: 0,
downloads: 0,
views: 0,
mime_type: "",
availability: "",
+ abuse_type: "",
show_ads: false,
can_edit: false,
get_href: "",
+ info_href: "",
download_href: "",
icon_href: "",
}
-let current_list = {
+const list_struct = {
id: "",
title: "",
files: [],
download_href: "",
+ info_href: "",
+ can_edit: false,
}
+
+let loading = true
+let embedded = false
+let view_token = ""
+let ads_enabled = false
+
+let view = "" // file or gallery
+let file = file_struct
+let list = list_struct
+let is_list = false
+
let button_home
let list_navigator
let list_shuffle = false
let toggle_shuffle = () => {
list_shuffle = !list_shuffle
- list_navigator.set_shuffle(list_shuffle)
}
let sharebar
let sharebar_visible = false
let toggle_sharebar = () => {
if (navigator.share) {
- let name = current_file.name
+ let name = file.name
if (is_list) {
- name = current_list.title
+ name = list.title
}
navigator.share({
@@ -104,40 +118,109 @@ onMount(() => {
if (viewer_data.type === "list") {
open_list(viewer_data.api_response)
} else {
- open_file(viewer_data.api_response)
+ list.files = [viewer_data.api_response]
+ open_file_index(0)
}
-})
-const open_list = (list) => {
- list.download_href = window.api_endpoint+"/list/"+list.id+"/zip"
- list.files.forEach(file => {
- file_set_href(file)
+ ads_enabled = list.files[0].show_ads
+ loading = false
+})
+const reload = async () => {
+ loading = true
+ if (is_list) {
+ try {
+ const resp = await fetch(list.info_href);
+ if (resp.status >= 400) {
+ throw (await resp.json()).message
+ }
+
+ open_list(await resp.json())
+ } catch (err) {
+ alert(err)
+ }
+ } else {
+ try {
+ const resp = await fetch(file.info_href);
+ if (resp.status >= 400) {
+ throw (await resp.json()).message
+ }
+
+ list.files = [await resp.json()]
+ open_file_index(0)
+ } catch (err) {
+ alert(err)
+ }
+ }
+ loading = false
+}
+
+const open_list = async l => {
+ l.download_href = window.api_endpoint+"/list/"+l.id+"/zip"
+ l.info_href = window.api_endpoint+"/list/"+l.id
+ l.files.forEach(f => {
+ file_set_href(f)
})
- current_list = list
+ list = l
// Setting is_list to true activates the ListNavgator, which makes sure the
// correct file is opened
is_list = true
-}
-const open_file = (file) => {
- file_set_href(file)
- current_file = file
+ // Skip to the file defined in the link hash
+ let matches = location.hash.match(new RegExp('item=([^&]*)'))
+ let hashID = parseInt(matches ? matches[1] : null)
+ if (Number.isInteger(hashID)) {
+ // The URL contains an item number. Navigate to that item
+ view = "file"
+ open_file_index(parseInt(hashID))
+ } else {
+ view = "gallery"
+ }
+}
+const open_file_index = async index => {
+ if (index >= list.files.length) {
+ index = 0
+ } else if (index < 0) {
+ index = list.files.length - 1
+ }
+ console.debug("received request to open file", index)
+
+ file_set_href(list.files[index])
+ file = list.files[index]
+ view = "file"
+
+ if (is_list) {
+ // Wait for the ListNavigator to render
+ await tick()
+
+ // Update the URL
+ location.replace("#item=" + index)
+ list_navigator.set_item(index)
+ }
// Register a file view
- fetch(window.api_endpoint + "/file/" + current_file.id + "/view", {
+ fetch(window.api_endpoint + "/file/" + file.id + "/view", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "token=" + view_token
})
}
-
-const file_set_href = file => {
- file.get_href = window.api_endpoint+"/file/"+file.id
- file.download_href = window.api_endpoint+"/file/"+file.id+"?download"
- file.icon_href = window.api_endpoint+"/file/"+file.id+"/thumbnail"
- file.timeseries_href = window.api_endpoint+"/file/"+file.id+"/timeseries"
+const file_set_href = f => {
+ f.get_href = window.api_endpoint+"/file/"+f.id
+ f.info_href = window.api_endpoint+"/file/"+f.id+"/info"
+ f.download_href = window.api_endpoint+"/file/"+f.id+"?download"
+ f.icon_href = window.api_endpoint+"/file/"+f.id+"/thumbnail"
+ f.timeseries_href = window.api_endpoint+"/file/"+f.id+"/timeseries"
+}
+const toggle_gallery = () => {
+ if (view === "gallery") {
+ open_file_index(0)
+ } else {
+ location.replace("#gallery")
+ view = "gallery"
+ file = file_struct // Empty the file struct
+ }
}
let download_frame
@@ -149,12 +232,12 @@ let captcha_container
const download = () => {
if (!window.viewer_data.captcha_key) {
console.debug("Server doesn't support captcha, starting download")
- download_frame.src = current_file.download_href
+ download_frame.src = file.download_href
return
}
- if (current_file.availability === "") {
+ if (file.availability === "") {
console.debug("File is available, starting download")
- download_frame.src = current_file.download_href
+ download_frame.src = file.download_href
return
}
@@ -164,7 +247,7 @@ const download = () => {
// we trigger the download using the captcha token Google provided us with
let captcha_complete_callback = token => {
// Download the file using the recaptcha token
- download_frame.src = current_file.download_href + "&recaptcha_response=" + token
+ download_frame.src = file.download_href + "&recaptcha_response=" + token
download_captcha_window.hide()
}
@@ -180,10 +263,10 @@ const download = () => {
})
}
- if (current_file.availability === "file_rate_limited_captcha_required") {
+ if (file.availability === "file_rate_limited_captcha_required") {
captcha_type = "rate_limit"
captcha_window_title = "Rate limiting enabled!"
- } else if (current_file.availability === "virus_detected_captcha_required") {
+ } else if (file.availability === "virus_detected_captcha_required") {
captcha_type = "malware"
captcha_window_title = "Malware warning!"
}
@@ -202,7 +285,7 @@ const download = () => {
}
const download_list = () => {
if (is_list) {
- download_frame.src = current_list.download_href
+ download_frame.src = list.download_href
}
}
@@ -233,12 +316,12 @@ const copy_url = () => {
}
const grab_file = async () => {
- if (!window.user_authenticated || current_file.can_edit) {
+ if (!window.user_authenticated || file.can_edit) {
return
}
const form = new FormData()
- form.append("grab_file", current_file.id)
+ form.append("grab_file", file.id)
try {
const resp = await fetch(
@@ -297,7 +380,7 @@ const keyboard_event = evt => {
details_window.toggle()
break
case 69: // E to open the edit window
- if (current_file.can_edit) {
+ if (file.can_edit) {
edit_window.toggle()
}
break
@@ -321,6 +404,12 @@ const keyboard_event = evt => {
+ {#if loading}
+
diff --git a/svelte/src/file_viewer/viewers/File.svelte b/svelte/src/file_viewer/viewers/File.svelte
index 6715219..538850a 100644
--- a/svelte/src/file_viewer/viewers/File.svelte
+++ b/svelte/src/file_viewer/viewers/File.svelte
@@ -23,16 +23,22 @@ export let file = {
{dispatch("download")}}>
save Download
- {#if file.size > 1e9}
-
- Your download speed is currently limited to 4 MiB/s. Downloading this
- file for free will take {formatDuration((file.size/4194304)*1000)}.
-
- Upgrade to Pro
-
- to download at the fastest speed available.
- {/if}
+ {#if file.size > 5e8}
+
+
+
+
+ Your download speed is currently limited to 4 MiB/s. Downloading this
+ file for free will take at least
+ {formatDuration((file.size/4194304)*1000)}.
+ You can
+
+ upgrade to Pro
+
+ to download at the fastest speed available.
+
+ {/if}
diff --git a/svelte/src/user_home/HotlinkProgressBar.svelte b/svelte/src/user_home/HotlinkProgressBar.svelte
index 1fe9a22..dec816f 100644
--- a/svelte/src/user_home/HotlinkProgressBar.svelte
+++ b/svelte/src/user_home/HotlinkProgressBar.svelte
@@ -34,19 +34,3 @@ $: frac = used / total
{/if}
-
-