Block sharing if subscription does not support it
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { FSNavigator } from "./FSNavigator";
|
import type { FSNavigator } from "./FSNavigator";
|
||||||
import { fs_node_icon, fs_share_hotlink_url, fs_share_url, fs_update, type FSNode, type FSPermissions } from "lib/FilesystemAPI.svelte";
|
import { fs_check_is_error, fs_node_icon, fs_share_hotlink_url, fs_share_url, fs_update, type FSNode, type FSPermissions } from "lib/FilesystemAPI.svelte";
|
||||||
import { copy_text } from "util/Util";
|
import { copy_text } from "util/Util";
|
||||||
import CopyButton from "layout/CopyButton.svelte";
|
import CopyButton from "layout/CopyButton.svelte";
|
||||||
import Dialog from "layout/Dialog.svelte";
|
import Dialog from "layout/Dialog.svelte";
|
||||||
import { fade } from "svelte/transition";
|
import { fade } from "svelte/transition";
|
||||||
|
import { get_user } from "lib/NovaAPI";
|
||||||
|
|
||||||
let { nav }: {
|
let { nav }: {
|
||||||
nav: FSNavigator;
|
nav: FSNavigator;
|
||||||
@@ -19,13 +20,33 @@ let is_parent = $state(false)
|
|||||||
let parent_node: FSNode = $state()
|
let parent_node: FSNode = $state()
|
||||||
|
|
||||||
let dialog: Dialog = $state()
|
let dialog: Dialog = $state()
|
||||||
|
let dialog_not_allowed: Dialog = $state()
|
||||||
export const open = async (e: MouseEvent, p: FSNode[]) => {
|
export const open = async (e: MouseEvent, p: FSNode[]) => {
|
||||||
path = p
|
path = p
|
||||||
base = path[path.length-1]
|
base = path[path.length-1]
|
||||||
|
|
||||||
|
const user = await get_user()
|
||||||
|
if (user.subscription.file_sharing === false && base.created_by === user.id) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
share_url = fs_share_url(path)
|
share_url = fs_share_url(path)
|
||||||
if (share_url === "") {
|
if (share_url === "") {
|
||||||
// File is not public, make public
|
// File is not public, make public
|
||||||
|
try {
|
||||||
await make_public()
|
await make_public()
|
||||||
|
} catch (err) {
|
||||||
|
if (fs_check_is_error(err, "sharing_not_allowed")) {
|
||||||
|
if (e.target instanceof HTMLButtonElement) {
|
||||||
|
dialog_not_allowed.open(e.target.getBoundingClientRect())
|
||||||
|
} else {
|
||||||
|
dialog_not_allowed.open((e.target as HTMLElement).parentElement.getBoundingClientRect())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
alert("Error file making file public: "+err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await share()
|
await share()
|
||||||
@@ -85,6 +106,16 @@ const share = async () => {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<Dialog bind:this={dialog_not_allowed}>
|
||||||
|
<div class="dialog_inner">
|
||||||
|
<div class="highlight_yellow" transition:fade>
|
||||||
|
Sharing is not allowed on free accounts. Upgrade to premium to
|
||||||
|
enable this feature
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
<Dialog bind:this={dialog}>
|
<Dialog bind:this={dialog}>
|
||||||
<div class="dialog_inner">
|
<div class="dialog_inner">
|
||||||
{#if toast !== ""}
|
{#if toast !== ""}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import BrandingOptions from "./BrandingOptions.svelte";
|
|||||||
import { branding_from_props } from "./Branding";
|
import { branding_from_props } from "./Branding";
|
||||||
import FileOptions from "./FileOptions.svelte";
|
import FileOptions from "./FileOptions.svelte";
|
||||||
import SharingOptions from "./SharingOptions.svelte";
|
import SharingOptions from "./SharingOptions.svelte";
|
||||||
import AccessControl from "./AccessControl.svelte";
|
|
||||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||||
import { loading_finish, loading_start } from "lib/Loading";
|
import { loading_finish, loading_start } from "lib/Loading";
|
||||||
|
|
||||||
@@ -120,12 +119,6 @@ const save = async (e: SubmitEvent) => {
|
|||||||
<i class="icon">share</i>
|
<i class="icon">share</i>
|
||||||
Sharing
|
Sharing
|
||||||
</button>
|
</button>
|
||||||
{#if $nav.permissions.owner}
|
|
||||||
<button class:button_highlight={tab === "access"} onclick={() => tab = "access"}>
|
|
||||||
<i class="icon">key</i>
|
|
||||||
Access control
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
<button class:button_highlight={tab === "branding"} onclick={() => tab = "branding"}>
|
<button class:button_highlight={tab === "branding"} onclick={() => tab = "branding"}>
|
||||||
<i class="icon">palette</i>
|
<i class="icon">palette</i>
|
||||||
Branding
|
Branding
|
||||||
@@ -148,8 +141,6 @@ const save = async (e: SubmitEvent) => {
|
|||||||
bind:file
|
bind:file
|
||||||
bind:options
|
bind:options
|
||||||
/>
|
/>
|
||||||
{:else if tab === "access"}
|
|
||||||
<AccessControl bind:options />
|
|
||||||
{:else if tab === "branding"}
|
{:else if tab === "branding"}
|
||||||
<BrandingOptions
|
<BrandingOptions
|
||||||
bind:enabled={branding_enabled}
|
bind:enabled={branding_enabled}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { run } from 'svelte/legacy';
|
|
||||||
import { domain_url } from "util/Util";
|
import { domain_url } from "util/Util";
|
||||||
import CopyButton from "layout/CopyButton.svelte";
|
import CopyButton from "layout/CopyButton.svelte";
|
||||||
import { formatDate } from "util/Formatting";
|
import { formatDate } from "util/Formatting";
|
||||||
import { type FSNode, type NodeOptions } from "lib/FilesystemAPI.svelte";
|
import { type FSNode, type NodeOptions } from "lib/FilesystemAPI.svelte";
|
||||||
import AccessControl from "./AccessControl.svelte";
|
import AccessControl from "./AccessControl.svelte";
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { user } from "lib/UserStore";
|
||||||
|
|
||||||
let {
|
let {
|
||||||
file = $bindable(),
|
file = $bindable(),
|
||||||
@@ -45,11 +46,18 @@ const toggle_example = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let share_link = $derived(window.location.protocol+"//"+window.location.host+"/d/"+file.id)
|
let share_link = $derived(window.location.protocol+"//"+window.location.host+"/d/"+file.id)
|
||||||
run(() => {
|
onMount(() => {
|
||||||
embed_iframe(file, options)
|
embed_iframe(file, options)
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if $user.subscription.file_sharing === false}
|
||||||
|
<div class="highlight_yellow">
|
||||||
|
Your account does not support sharing features. Access controls will not
|
||||||
|
have any effect until you upgrade to premium.
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Public link</legend>
|
<legend>Public link</legend>
|
||||||
|
|
||||||
|
|||||||
@@ -314,6 +314,26 @@ export const fs_check_response = async (resp: Response) => {
|
|||||||
return JSON.parse(text)
|
return JSON.parse(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fs_check_is_error = (err: any, target: string) => {
|
||||||
|
if (typeof err.value !== "string") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err.value === target) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err.value === "multiple_errors" && Array.isArray(err.errors)) {
|
||||||
|
for (const embedded_err of err.errors) {
|
||||||
|
if (embedded_err.value === target) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export const fs_path_url = (path: string) => {
|
export const fs_path_url = (path: string) => {
|
||||||
if (!path || path.length === 0) {
|
if (!path || path.length === 0) {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user