feat(disable archive): Allow disabling archive functionality

also don't display content pane when archive or scraping is disabled

fixes #2009

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2024-01-28 12:55:09 +01:00
parent 4121990c3e
commit 6fe0d9ef67
5 changed files with 57 additions and 52 deletions

View File

@ -35,46 +35,18 @@ class CrawlService {
public const READ_TIMEOUT = 10;
public const UA_FIREFOX = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0';
/**
* @var BookmarkMapper
*/
private $bookmarkMapper;
/**
* @var BookmarkPreviewer
*/
private $bookmarkPreviewer;
/**
* @var FaviconPreviewer
*/
private $faviconPreviewer;
/**
* @var IConfig
*/
private $config;
private $path;
private $rootFolder;
/**
* @var IL10N
*/
private $l;
/**
* @var MimeTypes
*/
private $mimey;
/**
* @var LoggerInterface
*/
private $logger;
private MimeTypes $mimey;
public function __construct(BookmarkMapper $bookmarkMapper, BookmarkPreviewer $bookmarkPreviewer, FaviconPreviewer $faviconPreviewer, IConfig $config, IRootFolder $rootFolder, IL10N $l, LoggerInterface $logger) {
$this->bookmarkMapper = $bookmarkMapper;
$this->bookmarkPreviewer = $bookmarkPreviewer;
$this->faviconPreviewer = $faviconPreviewer;
$this->config = $config;
$this->rootFolder = $rootFolder;
$this->l = $l;
public function __construct(
private BookmarkMapper $bookmarkMapper,
private BookmarkPreviewer $bookmarkPreviewer,
private FaviconPreviewer $faviconPreviewer,
private IConfig $config,
private IRootFolder $rootFolder,
private IL10N $l,
private LoggerInterface $logger,
private UserSettingsService $userSettingsService) {
$this->mimey = new MimeTypes;
$this->logger = $logger;
}
/**
@ -104,8 +76,11 @@ class CrawlService {
}
if ($available) {
$this->archiveFile($bookmark, $resp);
$this->archiveContent($bookmark, $resp);
$this->userSettingsService->setUserId($bookmark->getUserId());
if (((boolean) $this->userSettingsService->get('archive.enabled')) === true) {
$this->archiveFile($bookmark, $resp);
$this->archiveContent($bookmark, $resp);
}
$this->bookmarkPreviewer->getImage($bookmark);
$this->faviconPreviewer->getImage($bookmark);
}

View File

@ -12,7 +12,7 @@ use OCP\IL10N;
class UserSettingsService {
public const KEYS = ['hasSeenWhatsnew', 'viewMode', 'archive.filePath', 'backup.enabled', 'backup.filePath', 'sorting'];
public const KEYS = ['hasSeenWhatsnew', 'viewMode', 'archive.enabled', 'archive.filePath', 'backup.enabled', 'backup.filePath', 'sorting'];
public function __construct(
private ?string $userId,
@ -23,6 +23,10 @@ class UserSettingsService {
}
public function setUserId(?string $userId): void {
$this->userId = $userId;
}
/**
* @param string $key
* @return string
@ -40,6 +44,12 @@ class UserSettingsService {
if ($key === 'limit') {
return $this->config->getAppValue('bookmarks', 'performance.maxBookmarksperAccount', 0);
}
if ($key === 'archive.enabled') {
$default = (string) true;
}
if ($key === 'privacy.enableScraping') {
return $this->config->getAppValue($this->appName, 'privacy.enableScraping', 'false');
}
if ($key === 'archive.filePath') {
$default = $this->l->t('Bookmarks');
}

View File

@ -5,7 +5,7 @@
-->
<template>
<div v-if="isActive && hasMinLength && !archivedFile && isWebLink" class="bookmark-content">
<div v-if="isActive && scrapingEnabled && archiveEnabled && hasMinLength && !archivedFile && isWebLink" class="bookmark-content">
<div v-if="bookmark.textContent" class="content" v-html="content" />
<div v-else>
<NcEmptyContent :title="t('bookmarks', 'Content pending')"
@ -37,6 +37,12 @@ export default {
isWebLink() {
return this.bookmark.url.startsWith('http')
},
scrapingEnabled() {
return this.$store.state.settings['privacy.enableScraping']
},
archiveEnabled() {
return this.$store.state.settings['archive.enabled']
},
bookmark() {
if (!this.isActive) return
return this.$store.getters.getBookmark(this.$store.state.sidebar.id)

View File

@ -17,14 +17,17 @@
<span class="icon-download" /> {{ t('bookmarks', 'Export') }}
</button>
<label><h3>{{ t('bookmarks', 'Archive path') }}</h3>
<p>{{ t('bookmarks',
'Enter the path of a folder in your Files where bookmarked files should be stored.'
) }}</p>
<input :value="archivePath"
:readonly="true"
@click="onChangeArchivePath">
</label>
<template v-if="scrapingEnabled">
<label><h3>{{ t('bookmarks', 'Archive path') }}</h3>
<p><label><input type="checkbox" :checked="archiveEnabled" @input="onChangeArchiveEnabled">{{ t('bookmarks', 'Enable bookmarks archiving to store the web contents of the links you bookmark') }}</label></p>
<p>{{ t('bookmarks',
'Enter the path of a folder in your Files where bookmarked files should be stored.'
) }}</p>
<input :value="archivePath"
:readonly="true"
@click="onChangeArchivePath">
</label>
</template>
<label><h3>{{ t('bookmarks', 'Backups') }}</h3>
<p><label><input type="checkbox" :checked="backupEnabled" @input="onChangeBackupEnabled">{{ t('bookmarks', 'Enable bookmarks backups') }}</label></p>
@ -110,6 +113,12 @@ export default {
}
return `javascript:(function(){var a=window,b=document,c=encodeURIComponent,e=c(document.title),d=a.open('${bookmarkletUrl}?url='+c(b.location)+'&title='+e${queryStringExtension},'bkmk_popup','left='+((a.screenX||a.screenLeft)+10)+',top='+((a.screenY||a.screenTop)+10)+',height=650px,width=550px,resizable=1,alwaysRaised=1');a.setTimeout(function(){d.focus()},300);})();`
},
scrapingEnabled() {
return Boolean(this.$store.state.settings['privacy.enableScraping'])
},
archiveEnabled() {
return Boolean(this.$store.state.settings['archive.enabled'])
},
archivePath() {
return this.$store.state.settings['archive.filePath']
},
@ -147,6 +156,12 @@ export default {
= 'bookmark/export?requesttoken='
+ encodeURIComponent(getRequestToken())
},
async onChangeArchiveEnabled(e) {
await this.$store.dispatch(actions.SET_SETTING, {
key: 'archive.enabled',
value: !this.archiveEnabled,
})
},
async onChangeArchivePath(e) {
const path = await this.archivePathPicker.pick()
await this.$store.dispatch(actions.SET_SETTING, {

View File

@ -152,8 +152,7 @@ export default {
editingTitle: false,
target: '',
editingTarget: false,
activeTab: '',
showContentModal: false,
activeTab: ''
}
},
computed: {