Skip to content

Commit

Permalink
metadata: add file path (fix #173)
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed Aug 25, 2023
1 parent 991babb commit 001c63a
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 21 deletions.
14 changes: 12 additions & 2 deletions lib/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ public function info(
int $id,
bool $basic = false,
bool $current = false,
bool $filepath = false,
bool $tags = false,
string $clusters = ''
): Http\Response {
return Util::guardEx(function () use ($id, $basic, $current, $tags, $clusters) {
return Util::guardEx(function () use ($id, $basic, $current, $filepath, $tags, $clusters) {
$file = $this->fs->getUserFile($id);

// Get the image info
Expand All @@ -202,7 +203,8 @@ public function info(
$info['basename'] = $file->getName();

// Allow these ony for logged in users
if (null !== $this->userSession->getUser()) {
$user = $this->userSession->getUser();
if (null !== $user) {
// Get list of tags for this file
if ($tags) {
$info['tags'] = $this->getTags($id);
Expand All @@ -213,6 +215,14 @@ public function info(
$info['current'] = Exif::getExifFromFile($file);
}

// Get the path of the file for the current user
if ($filepath) {
$parts = explode('/', $file->getPath());
if (\count($parts) > 3 && $parts[1] === $user->getUID()) {
$info['filepath'] = implode('/', \array_slice($parts, 3));
}
}

// Get clusters for this file
if ($clusters) {
$clist = [];
Expand Down
22 changes: 18 additions & 4 deletions lib/Controller/OtherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,30 @@ public function setUserConfig(string $key, string $value): Http\Response
public function getUserConfig(): Http\Response
{
return Util::guardEx(function () {
$appManager = \OC::$server->get(\OCP\App\IAppManager::class);
// get memories version
$version = \OC::$server->get(\OCP\App\IAppManager::class)
->getAppInfo('memories')['version'];

// get user if logged in
try {
$uid = Util::getUID();
} catch (\Exception $e) {
$uid = null;
}

// helper function to get user config values
$getAppConfig = function ($key, $default) use ($uid) {
return $this->config->getUserValue($uid, Application::APPNAME, $key, $default);
};

return new JSONResponse([
'version' => $appManager->getAppInfo('memories')['version'],
// general stuff
'version' => $version,
'vod_disable' => Util::getSystemConfig('memories.vod.disable'),
'video_default_quality' => Util::getSystemConfig('memories.video_default_quality'),
'places_gis' => Util::getSystemConfig('memories.gis_type'),

// enabled apps
'systemtags_enabled' => Util::tagsIsEnabled(),
'albums_enabled' => Util::albumsIsEnabled(),
'recognize_installed' => Util::recognizeIsInstalled(),
Expand All @@ -90,13 +96,21 @@ public function getUserConfig(): Http\Response
'facerecognition_enabled' => Util::facerecognitionIsEnabled(),
'preview_generator_enabled' => Util::previewGeneratorIsEnabled(),

// general settings
'timeline_path' => $getAppConfig('timelinePath', 'EMPTY'),
'enable_top_memories' => 'true' === $getAppConfig('enableTopMemories', 'true'),

// viewer settings
'livephoto_autoplay' => 'true' === $getAppConfig('livephotoAutoplay', 'true'),
'sidebar_filepath' => 'true' === $getAppConfig('sidebarFilepath', false),

// folder settings
'folders_path' => $getAppConfig('foldersPath', '/'),
'show_hidden_folders' => 'true' === $getAppConfig('showHidden', false),
'sort_folder_month' => 'true' === $getAppConfig('sortFolderMonth', false),

// album settings
'sort_album_month' => 'true' === $getAppConfig('sortAlbumMonth', 'true'),
'enable_top_memories' => 'true' === $getAppConfig('enableTopMemories', 'true'),
'livephoto_autoplay' => 'true' === $getAppConfig('livephotoAutoplay', 'true'),
], Http::STATUS_OK);
});
}
Expand Down
13 changes: 7 additions & 6 deletions src/components/Metadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ export default defineComponent({
});
}
if (this.imageInfo) {
if (this.filepath) {
list.push({
title: this.imageInfo,
title: this.filepath,
subtitle: this.imageInfoSub,
icon: ImageIcon,
});
Expand Down Expand Up @@ -287,8 +287,8 @@ export default defineComponent({
},
/** Image info */
imageInfo(): string | null {
return this.baseInfo.basename;
filepath(): string | null {
return this.baseInfo.filepath ?? this.baseInfo.basename;
},
imageInfoSub(): string[] {
Expand Down Expand Up @@ -382,10 +382,11 @@ export default defineComponent({
.join(',');
// get tags if enabled
const tags = this.config.systemtags_enabled ? 1 : 0;
const tags = Number(this.config.systemtags_enabled);
const filepath = Number(this.config.sidebar_filepath);
// get image info
const url = API.Q(utils.getImageInfoUrl(photo), { tags, clusters });
const url = API.Q(utils.getImageInfoUrl(photo), { tags, clusters, filepath });
const res = await this.guardState(axios.get<IImageInfo>(url));
if (!res) return null;
Expand Down
27 changes: 23 additions & 4 deletions src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
>
{{ t('memories', 'Show past photos on top of timeline') }}
</NcCheckboxRadioSwitch>
</NcAppSettingsSection>

<NcAppSettingsSection id="viewer-settings" :title="t('memories', 'Viewer')">
<NcCheckboxRadioSwitch
:checked.sync="config.livephoto_autoplay"
@update:checked="updateLivephotoAutoplay"
Expand All @@ -68,6 +70,14 @@
>
{{ t('memories', 'Always load full size image (not recommended)') }}
</NcCheckboxRadioSwitch>

<NcCheckboxRadioSwitch
:checked.sync="config.sidebar_filepath"
@update:checked="updateSidebarFilepath"
type="switch"
>
{{ t('memories', 'Show full file path in sidebar') }}
</NcCheckboxRadioSwitch>
</NcAppSettingsSection>

<NcAppSettingsSection id="account-settings" :title="t('memories', 'Account')" v-if="isNative">
Expand Down Expand Up @@ -197,6 +207,7 @@ export default defineComponent({
this.$emit('update:open', false);
},
// Paths settings
async chooseTimelinePath() {
(<any>this.$refs.multiPathModal).open(this.config.timeline_path.split(';'));
},
Expand All @@ -223,10 +234,16 @@ export default defineComponent({
}
},
// General settings
async updateSquareThumbs() {
await this.updateSetting('square_thumbs');
},
async updateEnableTopMemories() {
await this.updateSetting('enable_top_memories', 'enableTopMemories');
},
// Viewer settings
async updateFullResOnZoom() {
await this.updateSetting('full_res_on_zoom');
},
Expand All @@ -235,14 +252,15 @@ export default defineComponent({
await this.updateSetting('full_res_always');
},
async updateEnableTopMemories() {
await this.updateSetting('enable_top_memories', 'enableTopMemories');
},
async updateLivephotoAutoplay() {
await this.updateSetting('livephoto_autoplay', 'livephotoAutoplay');
},
async updateSidebarFilepath() {
await this.updateSetting('sidebar_filepath', 'sidebarFilepath');
},
// Folders settings
async updateShowHidden() {
await this.updateSetting('show_hidden_folders', 'showHidden');
},
Expand All @@ -251,6 +269,7 @@ export default defineComponent({
await this.updateSetting('sort_folder_month', 'sortFolderMonth');
},
// Albums settings
async updateSortAlbumMonth() {
await this.updateSetting('sort_album_month', 'sortAlbumMonth');
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/viewer/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ export default defineComponent({
* Open the files app with the current file.
*/
async viewInFolder() {
if (this.currentPhoto) dav.viewInFolder(this.currentPhoto);
dav.viewInFolder(this.currentPhoto!);
},
/**
Expand Down
1 change: 1 addition & 0 deletions src/services/dav/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { dirname } from 'path';
* Opens a new window.
*/
export async function viewInFolder(photo: IPhoto) {
if (!photo) return;
const f = await getFiles([photo]);
if (f.length === 0) return;

Expand Down
15 changes: 13 additions & 2 deletions src/services/static-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ class StaticConfig {
}

const config: IConfig = {
// general stuff
version: '',
vod_disable: false,
video_default_quality: '0',
places_gis: -1,

// enabled apps
systemtags_enabled: false,
albums_enabled: false,
recognize_installed: false,
Expand All @@ -110,14 +112,23 @@ class StaticConfig {
facerecognition_enabled: false,
preview_generator_enabled: false,

// general settings
timeline_path: '',
enable_top_memories: true,

// viewer settings
livephoto_autoplay: true,
sidebar_filepath: false,

// folder settings
folders_path: '',
show_hidden_folders: false,
sort_folder_month: false,

// album settings
sort_album_month: true,
enable_top_memories: true,
livephoto_autoplay: true,

// local settings
square_thumbs: false,
full_res_on_zoom: true,
full_res_always: false,
Expand Down
16 changes: 14 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface IImageInfo {
tags: { [id: string]: string };

permissions: string;
filepath?: string;
basename: string;
mimetype: string;
size: number;
Expand Down Expand Up @@ -230,11 +231,13 @@ export type ITick = {
};

export type IConfig = {
// general stuff
version: string;
vod_disable: boolean;
video_default_quality: string;
places_gis: number;

// enabled apps
systemtags_enabled: boolean;
albums_enabled: boolean;
recognize_installed: boolean;
Expand All @@ -243,14 +246,23 @@ export type IConfig = {
facerecognition_enabled: boolean;
preview_generator_enabled: boolean;

// general settings
timeline_path: string;
enable_top_memories: boolean;

// viewer settings
livephoto_autoplay: boolean;
sidebar_filepath: boolean;

// folder settings
folders_path: string;
show_hidden_folders: boolean;
sort_folder_month: boolean;

// album settings
sort_album_month: boolean;
enable_top_memories: boolean;
livephoto_autoplay: boolean;

// local settings
square_thumbs: boolean;
full_res_on_zoom: boolean;
full_res_always: boolean;
Expand Down

0 comments on commit 001c63a

Please sign in to comment.