Add custom branding links

This commit is contained in:
2022-05-03 16:38:48 +02:00
parent a3deaf73c3
commit b7b5edabb0
3 changed files with 76 additions and 23 deletions

View File

@@ -1,11 +1,18 @@
<script> <script>
export let src = "" export let src = ""
export let link = ""
export let border_top = false; export let border_top = false;
</script> </script>
{#if src} {#if src}
<div class:border_top> <div class:border_top>
{#if link}
<a href={link} target="_blank">
<img class="image" src="{src}" alt="User-provided banner"/> <img class="image" src="{src}" alt="User-provided banner"/>
</a>
{:else}
<img class="image" src="{src}" alt="User-provided banner"/>
{/if}
</div> </div>
{/if} {/if}

View File

@@ -228,8 +228,10 @@ const toggle_gallery = () => {
// any change // any change
let file_preview_background let file_preview_background
let custom_header = "" let custom_header = ""
let custom_header_link = ""
let custom_background = "" let custom_background = ""
let custom_footer = "" let custom_footer = ""
let custom_footer_link = ""
const apply_customizations = file => { const apply_customizations = file => {
if (!file.branding) { if (!file.branding) {
return return
@@ -237,9 +239,15 @@ const apply_customizations = file => {
if (file.branding.header_image) { if (file.branding.header_image) {
custom_header = window.api_endpoint+"/file/"+file.branding.header_image custom_header = window.api_endpoint+"/file/"+file.branding.header_image
} }
if (file.branding.header_link) {
custom_header_link = file.branding.header_link
}
if (file.branding.footer_image) { if (file.branding.footer_image) {
custom_footer = window.api_endpoint+"/file/"+file.branding.footer_image custom_footer = window.api_endpoint+"/file/"+file.branding.footer_image
} }
if (file.branding.footer_link) {
custom_footer_link = file.branding.footer_link
}
if (file.branding.background_image) { if (file.branding.background_image) {
custom_background = window.api_endpoint+"/file/"+file.branding.background_image custom_background = window.api_endpoint+"/file/"+file.branding.background_image
@@ -410,7 +418,7 @@ const keyboard_event = evt => {
</ListNavigator> </ListNavigator>
{/if} {/if}
<CustomBanner src={custom_header} border_top={true}></CustomBanner> <CustomBanner src={custom_header} link={custom_header_link} border_top={true}></CustomBanner>
<div class="file_preview_row"> <div class="file_preview_row">
<div id="toolbar" class="toolbar" class:toolbar_visible> <div id="toolbar" class="toolbar" class:toolbar_visible>
@@ -581,7 +589,7 @@ const keyboard_event = evt => {
{#if ads_enabled} {#if ads_enabled}
<AdLeaderboard></AdLeaderboard> <AdLeaderboard></AdLeaderboard>
{:else if custom_footer} {:else if custom_footer}
<CustomBanner src={custom_footer}></CustomBanner> <CustomBanner src={custom_footer} link={custom_footer_link}></CustomBanner>
{/if} {/if}
<Modal bind:this={details_window} on:is_visible={e => {details_visible = e.detail}} title="File details" width="1200px"> <Modal bind:this={details_window} on:is_visible={e => {details_visible = e.detail}} title="File details" width="1200px">

View File

@@ -13,8 +13,10 @@ let currently_selecting = "" // header, background or footer
let theme = "" let theme = ""
let header_image = "" let header_image = ""
let header_link = ""
let background_image = "" let background_image = ""
let footer_image = "" let footer_image = ""
let footer_link = ""
let select_file = t => { let select_file = t => {
currently_selecting = t currently_selecting = t
@@ -47,9 +49,12 @@ let save = async () => {
const form = new FormData() const form = new FormData()
form.append("theme", theme) form.append("theme", theme)
form.append("header_image", header_image) form.append("header_image", header_image)
form.append("header_link", header_link)
form.append("background_image", background_image) form.append("background_image", background_image)
form.append("footer_image", footer_image) form.append("footer_image", footer_image)
form.append("footer_link", footer_link)
try {
const resp = await fetch( const resp = await fetch(
window.api_endpoint+"/user/file_customization", window.api_endpoint+"/user/file_customization",
{ method: "PUT", body: form } { method: "PUT", body: form }
@@ -57,21 +62,29 @@ let save = async () => {
if(resp.status >= 400) { if(resp.status >= 400) {
let json = await resp.json() let json = await resp.json()
console.debug(json) console.debug(json)
success_message.set(false, json.message) throw json.message
return
} }
success_message.set(true, "Changes saved") success_message.set(true, "Changes saved")
} catch(err) {
success_message.set(false, err)
} finally {
loading = false loading = false
}
} }
onMount(() => { onMount(() => {
// The fields are undefined when they're empty. So we need to check if each
// field is defined before converting to a string
if (window.user.file_viewer_branding) { if (window.user.file_viewer_branding) {
let b = window.user.file_viewer_branding let b = window.user.file_viewer_branding
theme = b.theme ? b.theme : "" theme = b.theme ? b.theme : ""
header_image = b.header_image ? b.header_image : "" header_image = b.header_image ? b.header_image : ""
header_link = b.header_link ? b.header_link : ""
background_image = b.background_image ? b.background_image : "" background_image = b.background_image ? b.background_image : ""
footer_image = b.footer_image ? b.footer_image : "" footer_image = b.footer_image ? b.footer_image : ""
footer_link = b.footer_link ? b.footer_link : ""
} }
}) })
@@ -80,20 +93,19 @@ onMount(() => {
<LoadingIndicator loading={loading}/> <LoadingIndicator loading={loading}/>
<section> <section>
<h2>File viewer branding</h2>
{#if !window.user.subscription.file_viewer_branding} {#if !window.user.subscription.file_viewer_branding}
<div class="highlight_red"> <div class="highlight_red">
File viewer branding is not available for your account. Subscribe to Sharing settings are not available for your account. Subscribe to
the Persistence plan or higher to enable this feature. the Persistence plan or higher to enable these features.
</div> </div>
{:else if !window.user.hotlinking_enabled} {:else if !window.user.hotlinking_enabled}
<div class="highlight_red"> <div class="highlight_red">
To use the branding feature bandwidth sharing needs to be enabled. To use the sharing settings bandwidth sharing needs to be enabled.
Without this the custom images will not be able to load. Enable Enable bandwidth sharing on the
bandwidth sharing on the
<a href="/user/subscription">subscription page</a>. <a href="/user/subscription">subscription page</a>.
</div> </div>
{/if} {/if}
<h2>File viewer branding</h2>
<SuccessMessage bind:this={success_message}></SuccessMessage> <SuccessMessage bind:this={success_message}></SuccessMessage>
<p> <p>
You can change the appearance of your file viewer pages. The images you You can change the appearance of your file viewer pages. The images you
@@ -120,7 +132,8 @@ onMount(() => {
<h3>Header image</h3> <h3>Header image</h3>
<p> <p>
Will be shown above the file. Maximum height is 90px. Will be shrunk if Will be shown above the file. Maximum height is 90px. Will be shrunk if
larger. larger. You can also add a link to open when the visitor clicks the
image. The link need to start with 'https://'.
</p> </p>
<button on:click={() => {select_file("header")}}> <button on:click={() => {select_file("header")}}>
<i class="icon">add_photo_alternate</i> <i class="icon">add_photo_alternate</i>
@@ -130,9 +143,22 @@ onMount(() => {
<i class="icon">close</i> <i class="icon">close</i>
Remove Remove
</button> </button>
<br/>
<form on:submit|preventDefault={save}>
Header image link:
<input bind:value={header_link} type="text" placeholder="https://"/>
<button action="submit"><i class="icon">save</i> Save</button>
</form>
{#if header_image} {#if header_image}
<div class="highlight_shaded"> <div class="highlight_shaded">
{#if header_link}
<a href={header_link} target="_blank">
<img class="banner_preview" src="/api/file/{header_image}" alt="Custom file viewer header"/> <img class="banner_preview" src="/api/file/{header_image}" alt="Custom file viewer header"/>
</a>
{:else}
<img class="banner_preview" src="/api/file/{header_image}" alt="Custom file viewer header"/>
{/if}
</div> </div>
{/if} {/if}
@@ -170,9 +196,21 @@ onMount(() => {
<i class="icon">close</i> <i class="icon">close</i>
Remove Remove
</button> </button>
<br/>
<form on:submit|preventDefault={save}>
Footer image link:
<input bind:value={footer_link} type="text" placeholder="https://"/>
<button action="submit"><i class="icon">save</i> Save</button>
</form>
{#if footer_image} {#if footer_image}
<div class="highlight_shaded"> <div class="highlight_shaded">
{#if footer_link}
<a href={footer_link} target="_blank">
<img class="banner_preview" src="/api/file/{footer_image}" alt="Custom file viewer footer"/> <img class="banner_preview" src="/api/file/{footer_image}" alt="Custom file viewer footer"/>
</a>
{:else}
<img class="banner_preview" src="/api/file/{footer_image}" alt="Custom file viewer footer"/>
{/if}
</div> </div>
{/if} {/if}
<br/> <br/>