share: refactor refreshing list
parent
3bb152672b
commit
5a571b29b7
|
@ -55,26 +55,7 @@ class ShareController extends ApiBase
|
||||||
], Http::STATUS_NOT_FOUND);
|
], Http::STATUS_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \OCP\IURLGenerator $urlGenerator */
|
$links = array_map([$this, 'makeShareResponse'], $shares);
|
||||||
$urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class);
|
|
||||||
|
|
||||||
$links = array_map(function (\OCP\Share\IShare $share) use ($urlGenerator) {
|
|
||||||
$tok = $share->getToken();
|
|
||||||
$exp = $share->getExpirationDate();
|
|
||||||
$url = $urlGenerator->linkToRouteAbsolute('memories.Public.showShare', [
|
|
||||||
'token' => $tok,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'id' => $share->getFullId(),
|
|
||||||
'label' => $share->getLabel(),
|
|
||||||
'token' => $tok,
|
|
||||||
'url' => $url,
|
|
||||||
'hasPassword' => $share->getPassword() ? true : false,
|
|
||||||
'expiration' => $exp ? $exp->getTimestamp() : null,
|
|
||||||
'editable' => $share->getPermissions() & \OCP\Constants::PERMISSION_UPDATE,
|
|
||||||
];
|
|
||||||
}, $shares);
|
|
||||||
|
|
||||||
return new JSONResponse($links, Http::STATUS_OK);
|
return new JSONResponse($links, Http::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
@ -106,11 +87,9 @@ class ShareController extends ApiBase
|
||||||
$share->setSharedBy($this->userSession->getUser()->getUID());
|
$share->setSharedBy($this->userSession->getUser()->getUID());
|
||||||
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
|
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
|
||||||
|
|
||||||
$shareManager->createShare($share);
|
$share = $shareManager->createShare($share);
|
||||||
|
|
||||||
return new JSONResponse([
|
return new JSONResponse($this->makeShareResponse($share), Http::STATUS_OK);
|
||||||
'token' => $share->getToken(),
|
|
||||||
], Http::STATUS_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,8 +133,12 @@ class ShareController extends ApiBase
|
||||||
if ($id) {
|
if ($id) {
|
||||||
$file = $this->getUserFile($id);
|
$file = $this->getUserFile($id);
|
||||||
} elseif ($path) {
|
} elseif ($path) {
|
||||||
|
try {
|
||||||
$userFolder = $this->rootFolder->getUserFolder($uid);
|
$userFolder = $this->rootFolder->getUserFolder($uid);
|
||||||
$file = $userFolder->get($path);
|
$file = $userFolder->get($path);
|
||||||
|
} catch (\OCP\Files\NotFoundException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$file || !$file->isShareable()) {
|
if (!$file || !$file->isShareable()) {
|
||||||
|
@ -164,4 +147,25 @@ class ShareController extends ApiBase
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function makeShareResponse(\OCP\Share\IShare $share) {
|
||||||
|
/** @var \OCP\IURLGenerator $urlGenerator */
|
||||||
|
$urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class);
|
||||||
|
|
||||||
|
$tok = $share->getToken();
|
||||||
|
$exp = $share->getExpirationDate();
|
||||||
|
$url = $urlGenerator->linkToRouteAbsolute('memories.Public.showShare', [
|
||||||
|
'token' => $tok,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $share->getFullId(),
|
||||||
|
'label' => $share->getLabel(),
|
||||||
|
'token' => $tok,
|
||||||
|
'url' => $url,
|
||||||
|
'hasPassword' => $share->getPassword() ? true : false,
|
||||||
|
'expiration' => $exp ? $exp->getTimestamp() : null,
|
||||||
|
'editable' => $share->getPermissions() & \OCP\Constants::PERMISSION_UPDATE,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,9 +68,10 @@ export default defineComponent({
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.sidebar) {
|
if (this.sidebar) {
|
||||||
globalThis.mSidebar.open({
|
globalThis.mSidebar.open({ filename: this.sidebar } as any);
|
||||||
filename: this.sidebar,
|
|
||||||
} as any);
|
// Adjust width anyway in case the sidebar is already open
|
||||||
|
this.handleAppSidebarOpen();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -93,9 +94,9 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
handleAppSidebarOpen() {
|
handleAppSidebarOpen() {
|
||||||
this.isSidebarShown = true;
|
|
||||||
const sidebar: HTMLElement = document.querySelector("aside.app-sidebar");
|
const sidebar: HTMLElement = document.querySelector("aside.app-sidebar");
|
||||||
if (sidebar) {
|
if (sidebar) {
|
||||||
|
this.isSidebarShown = true;
|
||||||
this.sidebarWidth = sidebar.offsetWidth;
|
this.sidebarWidth = sidebar.offsetWidth;
|
||||||
this.trapElements = [sidebar];
|
this.trapElements = [sidebar];
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,9 @@
|
||||||
:title="share.label || t('memories', 'Share link')"
|
:title="share.label || t('memories', 'Share link')"
|
||||||
:key="share.id"
|
:key="share.id"
|
||||||
:bold="false"
|
:bold="false"
|
||||||
@click="copy(share.url)"
|
:href="share.url"
|
||||||
|
:compact="true"
|
||||||
|
@click.prevent="copy(share.url)"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<LinkIcon class="avatar" :size="20" />
|
<LinkIcon class="avatar" :size="20" />
|
||||||
|
@ -76,7 +78,6 @@ import { defineComponent } from "vue";
|
||||||
|
|
||||||
import axios from "@nextcloud/axios";
|
import axios from "@nextcloud/axios";
|
||||||
import { showSuccess } from "@nextcloud/dialogs";
|
import { showSuccess } from "@nextcloud/dialogs";
|
||||||
import { subscribe, unsubscribe } from "@nextcloud/event-bus";
|
|
||||||
|
|
||||||
import UserConfig from "../../mixins/UserConfig";
|
import UserConfig from "../../mixins/UserConfig";
|
||||||
import NcButton from "@nextcloud/vue/dist/Components/NcButton";
|
import NcButton from "@nextcloud/vue/dist/Components/NcButton";
|
||||||
|
@ -140,6 +141,7 @@ export default defineComponent({
|
||||||
methods: {
|
methods: {
|
||||||
open() {
|
open() {
|
||||||
this.show = true;
|
this.show = true;
|
||||||
|
this.shares = [];
|
||||||
globalThis.mSidebar.setTab("sharing");
|
globalThis.mSidebar.setTab("sharing");
|
||||||
this.refreshUrls();
|
this.refreshUrls();
|
||||||
},
|
},
|
||||||
|
@ -155,6 +157,8 @@ export default defineComponent({
|
||||||
this.shares = (
|
this.shares = (
|
||||||
await axios.get(API.Q(API.SHARE_LINKS(), { path: this.filename }))
|
await axios.get(API.Q(API.SHARE_LINKS(), { path: this.filename }))
|
||||||
).data;
|
).data;
|
||||||
|
} catch (e) {
|
||||||
|
this.shares = [];
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
|
@ -186,11 +190,15 @@ export default defineComponent({
|
||||||
async createLink() {
|
async createLink() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
await axios.post(API.SHARE_NODE(), { path: this.filename });
|
const res = await axios.post<IShare>(API.SHARE_NODE(), {
|
||||||
|
path: this.filename,
|
||||||
|
});
|
||||||
|
const share = res.data;
|
||||||
|
this.shares.push(share);
|
||||||
|
this.copy(share.url);
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
this.refreshUrls();
|
|
||||||
this.refreshSidebar();
|
this.refreshSidebar();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -212,9 +220,7 @@ export default defineComponent({
|
||||||
|
|
||||||
refreshSidebar() {
|
refreshSidebar() {
|
||||||
globalThis.mSidebar.close();
|
globalThis.mSidebar.close();
|
||||||
globalThis.mSidebar.open({
|
globalThis.mSidebar.open({ filename: this.filename } as any);
|
||||||
filename: this.filename,
|
|
||||||
} as any);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1034,12 +1034,15 @@ export default defineComponent({
|
||||||
|
|
||||||
/** Open the sidebar */
|
/** Open the sidebar */
|
||||||
async openSidebar(photo?: IPhoto) {
|
async openSidebar(photo?: IPhoto) {
|
||||||
let fInfo: IFileInfo | IPhoto = photo || this.currentPhoto;
|
|
||||||
if (!this.routeIsPublic) {
|
|
||||||
fInfo = (await dav.getFiles([fInfo]))[0];
|
|
||||||
}
|
|
||||||
globalThis.mSidebar.setTab("memories-metadata");
|
globalThis.mSidebar.setTab("memories-metadata");
|
||||||
globalThis.mSidebar.open(fInfo as IFileInfo);
|
globalThis.mSidebar.open(await this.getFileInfo(photo));
|
||||||
|
},
|
||||||
|
|
||||||
|
/** Get fileInfo for a photo */
|
||||||
|
async getFileInfo(photo?: IPhoto): Promise<IFileInfo> {
|
||||||
|
photo = photo || this.currentPhoto;
|
||||||
|
if (this.routeIsPublic) return photo as IFileInfo;
|
||||||
|
return (await dav.getFiles([photo]))[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
async updateSizeWithoutAnim() {
|
async updateSizeWithoutAnim() {
|
||||||
|
|
Loading…
Reference in New Issue