Skip to content

Commit

Permalink
feat(disable archive): Allow disabling archive functionality
Browse files Browse the repository at this point in the history
also don't display content pane when archive or scraping is disabled

fixes #2009

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 28, 2024
1 parent 4121990 commit 6fe0d9e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 52 deletions.
55 changes: 15 additions & 40 deletions lib/Service/CrawlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check failure on line 45 in lib/Service/CrawlService.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable28

MissingDependency

lib/Service/CrawlService.php:45:3: MissingDependency: OCP\Files\IRootFolder depends on class or interface oc\hooks\emitter that does not exist (see https://psalm.dev/157)

Check failure on line 45 in lib/Service/CrawlService.php

View workflow job for this annotation

GitHub Actions / Nextcloud v26.x.x

MissingDependency

lib/Service/CrawlService.php:45:3: MissingDependency: OCP\Files\IRootFolder depends on class or interface oc\hooks\emitter that does not exist (see https://psalm.dev/157)

Check failure on line 45 in lib/Service/CrawlService.php

View workflow job for this annotation

GitHub Actions / Nextcloud v27.1.x

MissingDependency

lib/Service/CrawlService.php:45:3: MissingDependency: OCP\Files\IRootFolder depends on class or interface oc\hooks\emitter that does not exist (see https://psalm.dev/157)
private IL10N $l,
private LoggerInterface $logger,
private UserSettingsService $userSettingsService) {
$this->mimey = new MimeTypes;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -104,8 +76,11 @@ public function crawl(Bookmark $bookmark): void {
}

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);
}
Expand Down
12 changes: 11 additions & 1 deletion lib/Service/UserSettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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,
Expand All @@ -23,6 +23,10 @@ public function __construct(

}

public function setUserId(?string $userId): void {
$this->userId = $userId;
}

/**
* @param string $key
* @return string
Expand All @@ -40,6 +44,12 @@ public function get(string $key): string {
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');
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/BookmarkContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Check warning on line 9 in src/components/BookmarkContent.vue

View workflow job for this annotation

GitHub Actions / eslint node16.x

'v-html' directive can lead to XSS attack
<div v-else>
<NcEmptyContent :title="t('bookmarks', 'Content pending')"
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 23 additions & 8 deletions src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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']
},
Expand Down Expand Up @@ -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, {
Expand Down
3 changes: 1 addition & 2 deletions src/components/SidebarBookmark.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ export default {
editingTitle: false,
target: '',
editingTarget: false,
activeTab: '',
showContentModal: false,
activeTab: ''

Check warning on line 155 in src/components/SidebarBookmark.vue

View workflow job for this annotation

GitHub Actions / eslint node16.x

Missing trailing comma
}
},
computed: {
Expand Down

0 comments on commit 6fe0d9e

Please sign in to comment.