mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Merge pull request #1838 from appwrite/remove-jwt
Remove JWT from File Tokens
This commit is contained in:
24 files changed
+145
-233
No files matched your search
+1
-1
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@ai-sdk/svelte": "^1.1.24",
|
||||
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1960",
|
||||
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959",
|
||||
"@appwrite.io/pink": "0.25.0",
|
||||
"@appwrite.io/pink-icons": "0.25.0",
|
||||
"@appwrite.io/pink-icons-svelte": "https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@d68e5e4",
|
||||
|
||||
Generated
+5
-5
@@ -12,8 +12,8 @@ importers:
|
||||
specifier: ^1.1.24
|
||||
version: 1.1.24(svelte@5.25.3)(zod@3.24.3)
|
||||
'@appwrite.io/console':
|
||||
specifier: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1960
|
||||
version: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1960
|
||||
specifier: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959
|
||||
version: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959
|
||||
'@appwrite.io/pink':
|
||||
specifier: 0.25.0
|
||||
version: 0.25.0
|
||||
@@ -254,8 +254,8 @@ packages:
|
||||
'@analytics/type-utils@0.6.2':
|
||||
resolution: {integrity: sha512-TD+xbmsBLyYy/IxFimW/YL/9L2IEnM7/EoV9Aeh56U64Ify8o27HJcKjo38XY9Tcn0uOq1AX3thkKgvtWvwFQg==}
|
||||
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1960':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1960}
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959}
|
||||
version: 1.5.2
|
||||
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@b39a7c45d4b8ebf03059018d195141c8d2b7c221':
|
||||
@@ -3625,7 +3625,7 @@ snapshots:
|
||||
|
||||
'@analytics/type-utils@0.6.2': {}
|
||||
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1960': {}
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@1959': {}
|
||||
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@b39a7c45d4b8ebf03059018d195141c8d2b7c221(svelte@5.25.3)':
|
||||
dependencies:
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
$: isFree = org.billingPlan === BillingPlan.FREE;
|
||||
|
||||
// equal or above means unlimited!
|
||||
$: getCorrectSeatsCountValue = (count: number): string | number => {
|
||||
const getCorrectSeatsCountValue = (count: number): string | number => {
|
||||
// php int max is always larger than js
|
||||
const exceedsSafeLimit = count >= Number.MAX_SAFE_INTEGER;
|
||||
return exceedsSafeLimit ? 'Unlimited' : count || 0;
|
||||
|
||||
@@ -373,7 +373,11 @@
|
||||
</div>
|
||||
{:else}
|
||||
{@const mobileConfig = getMobileWindowConfig()}
|
||||
<!-- we don't need keydown because we show this only on mobile -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div
|
||||
tabindex="0"
|
||||
role="button"
|
||||
class:showing={!openModalOnMobile}
|
||||
class="card notification-card u-width-full-line"
|
||||
on:click={() => {
|
||||
|
||||
@@ -111,8 +111,6 @@
|
||||
return arrayValue;
|
||||
}
|
||||
}
|
||||
|
||||
$inspect(subSheets);
|
||||
</script>
|
||||
|
||||
<BottomSheet.Menu bind:isOpen={openBottomSheet} menu={filtersBottomSheet} />
|
||||
@@ -19,8 +19,6 @@
|
||||
filterCols: FilterData[];
|
||||
analyticsSource?: string;
|
||||
} = $props();
|
||||
|
||||
$inspect(filterCols);
|
||||
</script>
|
||||
|
||||
<Menu>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
$installation = installations.installations[0];
|
||||
}
|
||||
selectedInstallationId = installations.total ? installations.installations[0]?.$id : '';
|
||||
if (!!installations?.total) {
|
||||
if (installations?.total) {
|
||||
repositoryBehaviour = 'existing';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
import { page } from '$app/state';
|
||||
import Card from '../card.svelte';
|
||||
import SkeletonRepoList from './skeletonRepoList.svelte';
|
||||
import { untrack } from 'svelte';
|
||||
|
||||
let {
|
||||
action = $bindable('select'),
|
||||
@@ -42,13 +43,13 @@
|
||||
} = $props();
|
||||
|
||||
let search = $state('');
|
||||
let selectedInstallation: string = null;
|
||||
let selectedInstallation = $state(null);
|
||||
let isLoadingRepositories = $state(null);
|
||||
|
||||
async function loadInstallations() {
|
||||
if (installationList) {
|
||||
if (installationList.installations.length) {
|
||||
selectedInstallation = installationList.installations[0].$id;
|
||||
untrack(() => (selectedInstallation = installationList.installations[0].$id));
|
||||
installation.set(
|
||||
installationList.installations.find(
|
||||
(entry) => entry.$id === selectedInstallation
|
||||
@@ -61,7 +62,7 @@
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.vcs.listInstallations();
|
||||
if (installations.length) {
|
||||
selectedInstallation = installations[0].$id;
|
||||
untrack(() => (selectedInstallation = installations[0].$id));
|
||||
installation.set(installations.find((entry) => entry.$id === selectedInstallation));
|
||||
}
|
||||
return installations;
|
||||
@@ -110,8 +111,6 @@
|
||||
$repositories.search = search;
|
||||
$repositories.installationId = installationId;
|
||||
}
|
||||
|
||||
$inspect(selectedRepository);
|
||||
</script>
|
||||
|
||||
{#if hasInstallations}
|
||||
|
||||
@@ -378,6 +378,18 @@ export const scopes: {
|
||||
category: 'Other',
|
||||
icon: 'globe'
|
||||
},
|
||||
{
|
||||
scope: 'tokens.read',
|
||||
description: "Access to read your project's file tokens",
|
||||
category: 'Other',
|
||||
icon: 'globe'
|
||||
},
|
||||
{
|
||||
scope: 'tokens.write',
|
||||
description: 'Access to create file tokens',
|
||||
category: 'Other',
|
||||
icon: 'globe'
|
||||
},
|
||||
{
|
||||
scope: 'sites.read',
|
||||
description: "Access to read your project's sites and deployments",
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
export let name: string = id;
|
||||
export let helper: string = undefined;
|
||||
export let value = '';
|
||||
export let pattern: string = null; //TODO: implement pattern check
|
||||
export let pattern: string = undefined; //TODO: implement pattern check
|
||||
export let patternError: string = '';
|
||||
export let placeholder = '';
|
||||
export let required = false;
|
||||
@@ -53,6 +53,7 @@
|
||||
{label}
|
||||
{nullable}
|
||||
{readonly}
|
||||
{pattern}
|
||||
autofocus={autofocus || undefined}
|
||||
autocomplete={autocomplete ? 'on' : 'off'}
|
||||
helper={error || helper}
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
showAccountMenu = false;
|
||||
}
|
||||
|
||||
$: progressCard = function getProgressCard() {
|
||||
const progressCard = function getProgressCard() {
|
||||
if (selectedProject && !hasOnboardingDismissed(selectedProject.$id)) {
|
||||
const currentProject = projects.find((project) => project.$id === selectedProject.$id);
|
||||
|
||||
|
||||
@@ -113,7 +113,6 @@ function createFeedbackStore() {
|
||||
currentPage: string,
|
||||
name?: string,
|
||||
email?: string,
|
||||
// eslint-disable-next-line
|
||||
billingPlan?: string,
|
||||
value?: number,
|
||||
orgId?: string,
|
||||
|
||||
+2
-2
@@ -113,7 +113,7 @@
|
||||
});
|
||||
};
|
||||
|
||||
$: customPolicyDescription = (policy: UserBackupPolicy) => {
|
||||
const customPolicyDescription = (policy: UserBackupPolicy) => {
|
||||
return backupPolicyDescription(
|
||||
policy.plainTextFrequency,
|
||||
null,
|
||||
@@ -123,7 +123,7 @@
|
||||
);
|
||||
};
|
||||
|
||||
$: formPolicyDescription = () => {
|
||||
const formPolicyDescription = () => {
|
||||
return backupPolicyDescription(
|
||||
policyFrequency,
|
||||
selectedTime,
|
||||
|
||||
+10
-9
@@ -29,15 +29,16 @@
|
||||
const ruleId = page.url.searchParams.get('rule');
|
||||
let isSubDomain = $derived(page.params.domain?.split('.')?.length >= 3);
|
||||
|
||||
let selectedTab: 'cname' | 'nameserver' | 'a' | 'aaaa' = $state(
|
||||
!!$consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain
|
||||
? 'cname'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_A
|
||||
? 'a'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_AAAA
|
||||
? 'aaaa'
|
||||
: 'nameserver'
|
||||
);
|
||||
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>('nameserver');
|
||||
$effect(() => {
|
||||
if ($consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain) {
|
||||
selectedTab = 'cname';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_A) {
|
||||
selectedTab = 'a';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_AAAA) {
|
||||
selectedTab = 'aaaa';
|
||||
}
|
||||
});
|
||||
let verified = $state(false);
|
||||
|
||||
let routeBase = `${base}/project-${page.params.region}-${page.params.project}/functions/function-${page.params.function}/domains`;
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
return [...baseRuntimes.values()];
|
||||
}
|
||||
|
||||
$: isChecked = (useCase: string) => {
|
||||
const isChecked = (useCase: string) => {
|
||||
return page.url.searchParams
|
||||
.getAll('useCase')
|
||||
.some((param) => param.toLowerCase() === useCase.toLowerCase());
|
||||
|
||||
+10
-9
@@ -29,15 +29,16 @@
|
||||
const ruleId = page.url.searchParams.get('rule');
|
||||
let isSubDomain = $derived(page.params.domain?.split('.')?.length >= 3);
|
||||
|
||||
let selectedTab: 'cname' | 'nameserver' | 'a' | 'aaaa' = $state(
|
||||
!!$consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain
|
||||
? 'cname'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_A
|
||||
? 'a'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_AAAA
|
||||
? 'aaaa'
|
||||
: 'nameserver'
|
||||
);
|
||||
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>('nameserver');
|
||||
$effect(() => {
|
||||
if ($consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain) {
|
||||
selectedTab = 'cname';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_A) {
|
||||
selectedTab = 'a';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_AAAA) {
|
||||
selectedTab = 'aaaa';
|
||||
}
|
||||
});
|
||||
let verified = $state(false);
|
||||
|
||||
let routeBase = `${base}/project-${page.params.region}-${page.params.project}/settings/domains`;
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@
|
||||
goto(target.toString());
|
||||
}
|
||||
|
||||
$: isChecked = (useCase: string) => {
|
||||
const isChecked = (useCase: string) => {
|
||||
return page.url.searchParams
|
||||
.getAll('useCase')
|
||||
.some((param) => param.toLowerCase() === useCase.toLowerCase());
|
||||
|
||||
+11
-9
@@ -29,15 +29,17 @@
|
||||
const ruleId = page.url.searchParams.get('rule');
|
||||
let isSubDomain = $derived(page.params.domain?.split('.')?.length >= 3);
|
||||
|
||||
let selectedTab: 'cname' | 'nameserver' | 'a' | 'aaaa' = $state(
|
||||
!!$consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain
|
||||
? 'cname'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_A
|
||||
? 'a'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_AAAA
|
||||
? 'aaaa'
|
||||
: 'nameserver'
|
||||
);
|
||||
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>('nameserver');
|
||||
$effect(() => {
|
||||
if ($consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain) {
|
||||
selectedTab = 'cname';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_A) {
|
||||
selectedTab = 'a';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_AAAA) {
|
||||
selectedTab = 'aaaa';
|
||||
}
|
||||
});
|
||||
|
||||
let verified = $state(false);
|
||||
|
||||
let routeBase = `${base}/project-${page.params.region}-${page.params.project}/sites/site-${page.params.site}/domains`;
|
||||
|
||||
+11
-9
@@ -25,15 +25,17 @@
|
||||
let isSubDomain = $derived.by(() =>
|
||||
selectedDomain?.domain?.length ? selectedDomain?.domain?.split('.')?.length >= 3 : false
|
||||
);
|
||||
let selectedTab: 'cname' | 'nameserver' | 'a' | 'aaaa' = $state(
|
||||
!!$consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain
|
||||
? 'cname'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_A
|
||||
? 'a'
|
||||
: !!$consoleVariables._APP_DOMAIN_TARGET_AAAA
|
||||
? 'aaaa'
|
||||
: 'nameserver'
|
||||
);
|
||||
|
||||
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>('nameserver');
|
||||
$effect(() => {
|
||||
if ($consoleVariables._APP_DOMAIN_TARGET_CNAME && isSubDomain) {
|
||||
selectedTab = 'cname';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_A) {
|
||||
selectedTab = 'a';
|
||||
} else if ($consoleVariables._APP_DOMAIN_TARGET_AAAA) {
|
||||
selectedTab = 'aaaa';
|
||||
}
|
||||
});
|
||||
|
||||
let verified = $state(false);
|
||||
|
||||
|
||||
+4
-50
@@ -29,14 +29,13 @@
|
||||
import {
|
||||
IconDotsHorizontal,
|
||||
IconDuplicate,
|
||||
IconKey,
|
||||
IconPencil,
|
||||
IconPlus,
|
||||
IconTrash
|
||||
} from '@appwrite.io/pink-icons-svelte';
|
||||
import FileTokensCopyUrl from './fileTokensCopyUrl.svelte';
|
||||
import ManageFileTokenModal, { cleanFormattedDate } from './manageFileToken.svelte';
|
||||
import { type Models, Permission, Role } from '@appwrite.io/console';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { isSmallViewport } from '$lib/stores/viewport';
|
||||
import { Menu } from '$lib/components/menu';
|
||||
import { SHOW_INIT_FEATURES } from '$lib/system';
|
||||
@@ -50,7 +49,6 @@
|
||||
let showManageToken = false;
|
||||
let tokenDeleteMode = false;
|
||||
let showCopyUrlModal = false;
|
||||
let tokenPermissionsMode = false;
|
||||
let selectedFileToken: Models.ResourceToken | null = null;
|
||||
|
||||
const getPreview = (fileId: string) =>
|
||||
@@ -124,9 +122,7 @@
|
||||
try {
|
||||
await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tokens.createFileToken($file.bucketId, $file.$id, expiry, [
|
||||
Permission.read(Role.any())
|
||||
]);
|
||||
.tokens.createFileToken($file.bucketId, $file.$id, expiry);
|
||||
|
||||
await invalidate(Dependencies.FILE_TOKENS);
|
||||
addNotification({
|
||||
@@ -149,11 +145,7 @@
|
||||
try {
|
||||
await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tokens.update(
|
||||
selectedFileToken.$id,
|
||||
fileToken.expire ? fileToken.expire : null,
|
||||
fileToken.$permissions
|
||||
);
|
||||
.tokens.update(selectedFileToken.$id, fileToken.expire ? fileToken.expire : null);
|
||||
await invalidate(Dependencies.FILE_TOKENS);
|
||||
addNotification({
|
||||
message: 'File token updated',
|
||||
@@ -171,23 +163,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function getPermissionGroups(token: Models.ResourceToken): string {
|
||||
const map = {
|
||||
read: 'Read',
|
||||
update: 'Update',
|
||||
delete: 'Delete'
|
||||
};
|
||||
|
||||
const groups = token.$permissions.reduce((set, perm) => {
|
||||
const match = perm.match(/^(\w+)\(/);
|
||||
const key = match?.[1] as keyof typeof map;
|
||||
if (key && map[key]) set.add(map[key]);
|
||||
return set;
|
||||
}, new Set<string>());
|
||||
|
||||
return [...groups].join(', ');
|
||||
}
|
||||
|
||||
function getExpiryDetails(token: Models.ResourceToken): {
|
||||
status: 'success' | 'warning' | 'error' | null;
|
||||
message: string | null;
|
||||
@@ -306,16 +281,6 @@
|
||||
? cleanFormattedDate(token.accessedAt, true)
|
||||
: 'Never'}</Table.Cell>
|
||||
|
||||
<Table.Cell column="permissions" {root}>
|
||||
{#if token.$permissions.length}
|
||||
<Typography.Text truncate>
|
||||
{getPermissionGroups(token)}
|
||||
</Typography.Text>
|
||||
{:else}
|
||||
none
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
|
||||
<Table.Cell column="actions" {root}>
|
||||
<Layout.Stack alignItems="flex-end">
|
||||
<Menu>
|
||||
@@ -345,20 +310,10 @@
|
||||
}}>
|
||||
Edit expiry
|
||||
</ActionMenu.Item.Button>
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconKey}
|
||||
on:click={() => {
|
||||
toggle();
|
||||
showManageToken = true;
|
||||
tokenPermissionsMode = true;
|
||||
selectedFileToken = token;
|
||||
}}>
|
||||
Edit permissions
|
||||
</ActionMenu.Item.Button>
|
||||
<ActionMenu.Item.Button
|
||||
status="danger"
|
||||
leadingIcon={IconTrash}
|
||||
on:click={async () => {
|
||||
on:click={() => {
|
||||
toggle();
|
||||
tokenDeleteMode = true;
|
||||
showManageToken = true;
|
||||
@@ -445,7 +400,6 @@
|
||||
bind:show={showManageToken}
|
||||
bind:isDelete={tokenDeleteMode}
|
||||
bind:fileToken={selectedFileToken}
|
||||
bind:isUpdatePermissions={tokenPermissionsMode}
|
||||
on:created={({ detail: expiry }) => createFileToken(expiry)}
|
||||
on:updated={({ detail: token }) => updateFileToken(token)}
|
||||
on:deleted={async () => await deleteFileToken(selectedFileToken)} />
|
||||
|
||||
+48
-85
@@ -1,79 +1,47 @@
|
||||
<script lang="ts">
|
||||
import { cachedJwts } from './store';
|
||||
import { page } from '$app/state';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { Modal, CopyInput } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Alert, Layout, Tabs, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { page } from '$app/state';
|
||||
|
||||
export let show = false;
|
||||
export let file: Models.File;
|
||||
export let token: Models.ResourceToken;
|
||||
|
||||
let error: boolean = null;
|
||||
|
||||
let codeSnippets = {};
|
||||
let tabContents = {};
|
||||
let selectedTab = 'Preview';
|
||||
|
||||
async function getJwtForToken(): Promise<string> {
|
||||
// Return cached, if it's valid based on the token's expiration.
|
||||
if ($cachedJwts.has(token.$id)) {
|
||||
const cachedJwt = $cachedJwts.get(token.$id);
|
||||
const isExpired = !!token.expire && new Date(token.expire) < new Date();
|
||||
|
||||
if (!isExpired) return cachedJwt;
|
||||
}
|
||||
|
||||
const { jwt } = await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tokens.getJWT(token.$id);
|
||||
|
||||
// update the cached object!
|
||||
cachedJwts.update((map) => {
|
||||
map.set(token.$id, jwt);
|
||||
return map;
|
||||
});
|
||||
|
||||
return jwt;
|
||||
}
|
||||
|
||||
function copyPreviewWithToken(
|
||||
token: string,
|
||||
method: 'preview' | 'view' | 'download' = 'preview'
|
||||
) {
|
||||
error = false;
|
||||
|
||||
try {
|
||||
let url: string;
|
||||
if (method === 'view') {
|
||||
url = sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.storage.getFileView(file.bucketId, file.$id);
|
||||
} else if (method === 'download') {
|
||||
url = sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.storage.getFileDownload(file.bucketId, file.$id);
|
||||
} else {
|
||||
url = sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.storage.getFilePreview(file.bucketId, file.$id);
|
||||
}
|
||||
|
||||
url = `${url}&token=${token}`;
|
||||
|
||||
return url;
|
||||
} catch (ignore) {
|
||||
error = true;
|
||||
let url: string;
|
||||
if (method === 'view') {
|
||||
url = sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.storage.getFileView(file.bucketId, file.$id);
|
||||
} else if (method === 'download') {
|
||||
url = sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.storage.getFileDownload(file.bucketId, file.$id);
|
||||
} else {
|
||||
url = sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.storage.getFilePreview(file.bucketId, file.$id);
|
||||
}
|
||||
|
||||
url = `${url}&token=${token}`;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
async function setCodeSnippets() {
|
||||
const jwt = await getJwtForToken();
|
||||
return {
|
||||
Preview: `${copyPreviewWithToken(jwt)}`,
|
||||
View: `${copyPreviewWithToken(jwt, 'view')}`,
|
||||
Download: `${copyPreviewWithToken(jwt, 'download')}`
|
||||
function setUrlSnippets() {
|
||||
tabContents = {
|
||||
Preview: `${copyPreviewWithToken(token.secret)}`,
|
||||
View: `${copyPreviewWithToken(token.secret, 'view')}`,
|
||||
Download: `${copyPreviewWithToken(token.secret, 'download')}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,42 +66,37 @@
|
||||
}
|
||||
|
||||
$: if (show) {
|
||||
setCodeSnippets().then((snippets) => (codeSnippets = snippets));
|
||||
setUrlSnippets();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal title="Copy File URL" bind:show hideFooter>
|
||||
{@const tokenUrl = tabContents[selectedTab]}
|
||||
<span slot="description"> Use the token-based URL below to access this file securely. </span>
|
||||
|
||||
{#if error}
|
||||
<Alert.Inline title="Error" status="error">
|
||||
Something went wrong, could not generate the URL.
|
||||
</Alert.Inline>
|
||||
{:else}
|
||||
{@const tokenUrl = codeSnippets[selectedTab]}
|
||||
<Layout.Stack gap="xl">
|
||||
<Tabs.Root let:root stretch>
|
||||
{#each ['Preview', 'View', 'Download'] as cat}
|
||||
<Tabs.Item.Button
|
||||
{root}
|
||||
on:click={() => (selectedTab = cat)}
|
||||
active={selectedTab === cat}>
|
||||
{cat}
|
||||
</Tabs.Item.Button>
|
||||
{/each}
|
||||
</Tabs.Root>
|
||||
<Layout.Stack gap="xl">
|
||||
<Tabs.Root let:root stretch>
|
||||
{#each ['Preview', 'View', 'Download'] as cat}
|
||||
<Tabs.Item.Button
|
||||
{root}
|
||||
on:click={() => (selectedTab = cat)}
|
||||
active={selectedTab === cat}>
|
||||
{cat}
|
||||
</Tabs.Item.Button>
|
||||
{/each}
|
||||
</Tabs.Root>
|
||||
|
||||
<Typography.Text variant="m-400">
|
||||
{getMoreInfo()}
|
||||
</Typography.Text>
|
||||
{#if !token.expire}
|
||||
<Alert.Inline title="No expiration date" status="warning">
|
||||
This token doesn't expire. Be cautious when sharing links.
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
<CopyInput value={tokenUrl} />
|
||||
</Layout.Stack>
|
||||
|
||||
<Typography.Text variant="m-400">
|
||||
{getMoreInfo()}
|
||||
</Typography.Text>
|
||||
{#if !token.expire}
|
||||
<Alert.Inline title="No expiration date" status="warning">
|
||||
This token doesn't expire. Be cautious when sharing links.
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
<CopyInput value={tokenUrl} />
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (show = false)}>Close</Button>
|
||||
</svelte:fragment>
|
||||
|
||||
+15
-31
@@ -13,27 +13,24 @@
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { Link } from '@appwrite.io/pink-svelte';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { Permissions } from '$lib/components/permissions';
|
||||
import { Confirm, ExpirationInput, Modal } from '$lib/components';
|
||||
|
||||
export let show = false;
|
||||
export let isDelete = false;
|
||||
export let isUpdatePermissions = false;
|
||||
export let fileToken: Models.ResourceToken | null = null;
|
||||
|
||||
$: expire = fileToken?.expire ?? null;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
function close() {
|
||||
function close(): void {
|
||||
show = false;
|
||||
expire = null;
|
||||
isDelete = false;
|
||||
fileToken = null;
|
||||
isUpdatePermissions = false;
|
||||
}
|
||||
|
||||
function handleFileToken() {
|
||||
function handleFileToken(): void {
|
||||
if (isDelete) {
|
||||
dispatch('deleted');
|
||||
} else {
|
||||
@@ -45,6 +42,10 @@
|
||||
close();
|
||||
}
|
||||
|
||||
function getModalTitle(): string {
|
||||
return `${fileToken ? 'Edit' : 'Create'} token${fileToken ? ' expiry' : ''}`;
|
||||
}
|
||||
|
||||
$: if (!show) {
|
||||
close();
|
||||
}
|
||||
@@ -68,41 +69,24 @@
|
||||
</p>
|
||||
</Confirm>
|
||||
{:else}
|
||||
<Modal
|
||||
bind:show
|
||||
size="s"
|
||||
onSubmit={handleFileToken}
|
||||
title={`${fileToken ? 'Edit' : 'Create'} file token`}>
|
||||
<Modal bind:show size="s" onSubmit={handleFileToken} title={getModalTitle()}>
|
||||
<!-- TODO: docs link needed-->
|
||||
<svelte:fragment slot="description">
|
||||
{#if fileToken}
|
||||
{#if isUpdatePermissions}
|
||||
Choose who can access or update your file using this token.
|
||||
<Link.Anchor
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href="https://appwrite.io/docs/advanced/platform/permissions">
|
||||
Learn more
|
||||
</Link.Anchor>.
|
||||
{:else}
|
||||
{@const formattedDate = cleanFormattedDate(fileToken.$createdAt)}
|
||||
Edit the expiry of the file token created on <b>{formattedDate}</b>.
|
||||
{/if}
|
||||
{@const formattedDate = cleanFormattedDate(fileToken.$createdAt)}
|
||||
Edit the expiry of the file token created on <b>{formattedDate}</b>.
|
||||
{:else}
|
||||
Create a file token to grant access to a file.
|
||||
<!-- TODO: @itznotabug, @adityaoberai need documentations link -->
|
||||
<Link.Anchor href="https://appwrite.com/docs/">Learn more</Link.Anchor>.
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
{#if isUpdatePermissions}
|
||||
<Permissions bind:permissions={fileToken.$permissions} hideOnClick />
|
||||
{:else}
|
||||
<ExpirationInput
|
||||
bind:value={expire}
|
||||
resourceType="token"
|
||||
selectorLabel="Expiry"
|
||||
dateSelectorLabel="Expiry date" />
|
||||
{/if}
|
||||
<ExpirationInput
|
||||
bind:value={expire}
|
||||
resourceType="token"
|
||||
selectorLabel="Expiry"
|
||||
dateSelectorLabel="Expiry date" />
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={close}>Cancel</Button>
|
||||
|
||||
-6
@@ -7,15 +7,9 @@ export const file = derived(page, ($page) => $page.data.file as Models.File);
|
||||
|
||||
export const tokens = derived(page, ($page) => $page.data.tokens as Models.ResourceTokenList);
|
||||
|
||||
/**
|
||||
* Caches JWTs in memory by `token.$id` to avoid regenerating them on each URL copy.
|
||||
*/
|
||||
export const cachedJwts = writable<Map<string, string>>(new Map<string, string>());
|
||||
|
||||
export const columns = writable<Column[]>([
|
||||
{ id: 'created', title: 'Created', type: 'datetime', width: 200 },
|
||||
{ id: 'expire', title: 'Expiration', type: 'datetime', width: 200 },
|
||||
{ id: 'last_accessed', title: 'Last accessed', type: 'datetime', width: 200 },
|
||||
{ id: 'permissions', title: 'Permissions', type: 'string', width: 200 },
|
||||
{ id: 'actions', title: '', type: 'string', width: 60 }
|
||||
]);
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
const options = units.map((v) => ({ label: v.name, value: v.name }));
|
||||
$: selectedUnit = $unit;
|
||||
|
||||
$: maxValue = function formMaxFileSize() {
|
||||
const maxValue = function formMaxFileSize() {
|
||||
return (service * 1000 * 1000) / units.find((unit) => unit.name === selectedUnit).value;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user