share: refactor refreshing list
parent
3bb152672b
commit
5a571b29b7
|
@ -55,26 +55,7 @@ class ShareController extends ApiBase
|
|||
], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
/** @var \OCP\IURLGenerator $urlGenerator */
|
||||
$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);
|
||||
$links = array_map([$this, 'makeShareResponse'], $shares);
|
||||
|
||||
return new JSONResponse($links, Http::STATUS_OK);
|
||||
}
|
||||
|
@ -106,11 +87,9 @@ class ShareController extends ApiBase
|
|||
$share->setSharedBy($this->userSession->getUser()->getUID());
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
|
||||
|
||||
$shareManager->createShare($share);
|
||||
$share = $shareManager->createShare($share);
|
||||
|
||||
return new JSONResponse([
|
||||
'token' => $share->getToken(),
|
||||
], Http::STATUS_OK);
|
||||
return new JSONResponse($this->makeShareResponse($share), Http::STATUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,8 +133,12 @@ class ShareController extends ApiBase
|
|||
if ($id) {
|
||||
$file = $this->getUserFile($id);
|
||||
} elseif ($path) {
|
||||
$userFolder = $this->rootFolder->getUserFolder($uid);
|
||||
$file = $userFolder->get($path);
|
||||
try {
|
||||
$userFolder = $this->rootFolder->getUserFolder($uid);
|
||||
$file = $userFolder->get($path);
|
||||
} catch (\OCP\Files\NotFoundException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$file || !$file->isShareable()) {
|
||||
|
@ -164,4 +147,25 @@ class ShareController extends ApiBase
|
|||
|
||||
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() {
|
||||
if (this.sidebar) {
|
||||
globalThis.mSidebar.open({
|
||||
filename: this.sidebar,
|
||||
} as any);
|
||||
globalThis.mSidebar.open({ 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() {
|
||||
this.isSidebarShown = true;
|
||||
const sidebar: HTMLElement = document.querySelector("aside.app-sidebar");
|
||||
if (sidebar) {
|
||||
this.isSidebarShown = true;
|
||||
this.sidebarWidth = sidebar.offsetWidth;
|
||||
this.trapElements = [sidebar];
|
||||
}
|
||||
|
|
|
@ -37,7 +37,9 @@
|
|||
:title="share.label || t('memories', 'Share link')"
|
||||
:key="share.id"
|
||||
:bold="false"
|
||||
@click="copy(share.url)"
|
||||
:href="share.url"
|
||||
:compact="true"
|
||||
@click.prevent="copy(share.url)"
|
||||
>
|
||||
<template #icon>
|
||||
<LinkIcon class="avatar" :size="20" />
|
||||
|
@ -76,7 +78,6 @@ import { defineComponent } from "vue";
|
|||
|
||||
import axios from "@nextcloud/axios";
|
||||
import { showSuccess } from "@nextcloud/dialogs";
|
||||
import { subscribe, unsubscribe } from "@nextcloud/event-bus";
|
||||
|
||||
import UserConfig from "../../mixins/UserConfig";
|
||||
import NcButton from "@nextcloud/vue/dist/Components/NcButton";
|
||||
|
@ -140,6 +141,7 @@ export default defineComponent({
|
|||
methods: {
|
||||
open() {
|
||||
this.show = true;
|
||||
this.shares = [];
|
||||
globalThis.mSidebar.setTab("sharing");
|
||||
this.refreshUrls();
|
||||
},
|
||||
|
@ -155,6 +157,8 @@ export default defineComponent({
|
|||
this.shares = (
|
||||
await axios.get(API.Q(API.SHARE_LINKS(), { path: this.filename }))
|
||||
).data;
|
||||
} catch (e) {
|
||||
this.shares = [];
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
|
@ -186,11 +190,15 @@ export default defineComponent({
|
|||
async createLink() {
|
||||
this.loading = true;
|
||||
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 {
|
||||
this.loading = false;
|
||||
}
|
||||
this.refreshUrls();
|
||||
this.refreshSidebar();
|
||||
},
|
||||
|
||||
|
@ -212,9 +220,7 @@ export default defineComponent({
|
|||
|
||||
refreshSidebar() {
|
||||
globalThis.mSidebar.close();
|
||||
globalThis.mSidebar.open({
|
||||
filename: this.filename,
|
||||
} as any);
|
||||
globalThis.mSidebar.open({ filename: this.filename } as any);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1034,12 +1034,15 @@ export default defineComponent({
|
|||
|
||||
/** Open the sidebar */
|
||||
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.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() {
|
||||
|
|
Loading…
Reference in New Issue