Block sharing if subscription does not support it
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
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 CopyButton from "layout/CopyButton.svelte";
|
||||
import Dialog from "layout/Dialog.svelte";
|
||||
import { fade } from "svelte/transition";
|
||||
import { get_user } from "lib/NovaAPI";
|
||||
|
||||
let { nav }: {
|
||||
nav: FSNavigator;
|
||||
@@ -19,13 +20,33 @@ let is_parent = $state(false)
|
||||
let parent_node: FSNode = $state()
|
||||
|
||||
let dialog: Dialog = $state()
|
||||
let dialog_not_allowed: Dialog = $state()
|
||||
export const open = async (e: MouseEvent, p: FSNode[]) => {
|
||||
path = p
|
||||
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)
|
||||
if (share_url === "") {
|
||||
// File is not public, make public
|
||||
await make_public()
|
||||
try {
|
||||
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()
|
||||
@@ -85,6 +106,16 @@ const share = async () => {
|
||||
}
|
||||
</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}>
|
||||
<div class="dialog_inner">
|
||||
{#if toast !== ""}
|
||||
|
||||
@@ -5,7 +5,6 @@ import BrandingOptions from "./BrandingOptions.svelte";
|
||||
import { branding_from_props } from "./Branding";
|
||||
import FileOptions from "./FileOptions.svelte";
|
||||
import SharingOptions from "./SharingOptions.svelte";
|
||||
import AccessControl from "./AccessControl.svelte";
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
|
||||
@@ -120,12 +119,6 @@ const save = async (e: SubmitEvent) => {
|
||||
<i class="icon">share</i>
|
||||
Sharing
|
||||
</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"}>
|
||||
<i class="icon">palette</i>
|
||||
Branding
|
||||
@@ -148,8 +141,6 @@ const save = async (e: SubmitEvent) => {
|
||||
bind:file
|
||||
bind:options
|
||||
/>
|
||||
{:else if tab === "access"}
|
||||
<AccessControl bind:options />
|
||||
{:else if tab === "branding"}
|
||||
<BrandingOptions
|
||||
bind:enabled={branding_enabled}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy';
|
||||
import { domain_url } from "util/Util";
|
||||
import CopyButton from "layout/CopyButton.svelte";
|
||||
import { formatDate } from "util/Formatting";
|
||||
import { type FSNode, type NodeOptions } from "lib/FilesystemAPI.svelte";
|
||||
import AccessControl from "./AccessControl.svelte";
|
||||
import { onMount } from 'svelte';
|
||||
import { user } from "lib/UserStore";
|
||||
|
||||
let {
|
||||
file = $bindable(),
|
||||
@@ -45,11 +46,18 @@ const toggle_example = () => {
|
||||
}
|
||||
|
||||
let share_link = $derived(window.location.protocol+"//"+window.location.host+"/d/"+file.id)
|
||||
run(() => {
|
||||
onMount(() => {
|
||||
embed_iframe(file, options)
|
||||
});
|
||||
</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>
|
||||
<legend>Public link</legend>
|
||||
|
||||
|
||||
@@ -314,6 +314,26 @@ export const fs_check_response = async (resp: Response) => {
|
||||
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) => {
|
||||
if (!path || path.length === 0) {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user