Skip to content

Commit

Permalink
✨ Albums can be downloaded as .zip ♻️ Private archive setting is now …
Browse files Browse the repository at this point in the history
…Private download
  • Loading branch information
MarceauKa committed Nov 10, 2019
1 parent 0331bdf commit ebbf328
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 26 deletions.
15 changes: 15 additions & 0 deletions app/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public function scopeHashIdIs(Builder $query, string $hash): Builder
return $query->where('id', app('hashid')->decode($hash));
}

public function canDownloadArchive(): bool
{
if ($this->post->is_private
&& auth()->check() === false) {
return false;
}

if (app('shaarli')->getPrivateDownload() === true
&& auth()->check() === false) {
return false;
}

return true;
}

public function registerMediaCollections()
{
$this->addMediaCollection('images')
Expand Down
35 changes: 35 additions & 0 deletions app/Http/Controllers/AlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use App\Album;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\MediaLibrary\Models\Media;

class AlbumController extends Controller
{
Expand All @@ -29,4 +32,36 @@ public function edit(Request $request, int $id)
'album' => $album,
]);
}

public function download(Request $request, int $id)
{
/** @var Album $album */
$album = Album::findOrFail($id);

if (false === $album->canDownloadArchive()) {
abort(404);
}

$name = sprintf('album-%s.zip', Str::slug($album->title));

if (Storage::exists('tmp/' . $name)) {
return Storage::download('tmp/' . $name, $name);
}

$zip = new \ZipArchive();

if ($zip->open(storage_path('app/tmp/' . $name), \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
$medias = $album->getMedia('images');

foreach ($medias as $item) {
/** @var Media $item */
$zip->addFile($item->getPath(), $item->file_name);
$zip->setCompressionName($item->file_name, \ZipArchive::CM_STORE);
}

$zip->close();
}

return $this->download($request, $id);
}
}
5 changes: 5 additions & 0 deletions app/Http/Resources/AlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
use Spatie\MediaLibrary\Models\Media;

class AlbumResource extends JsonResource
{
Expand All @@ -26,6 +27,9 @@ public function toArray($request)
'url_delete' => route('api.album.delete', $this->id),
'url_share' => route('api.share', $this->post->id),
]),
$this->mergeWhen($this->resource->canDownloadArchive(), [
'url_download' => route('album.download', $this->id),
])
];
}

Expand All @@ -34,6 +38,7 @@ protected function getAlbumImages(): array
return $this
->getMedia('images')
->transform(function ($item) {
/** @var Media $item */
return [
'name' => $item->name,
'size' => $item->human_readable_size,
Expand Down
2 changes: 1 addition & 1 deletion app/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function canDownloadArchive(): bool
return false;
}

if (app('shaarli')->getPrivateArchive() === true
if (app('shaarli')->getPrivateDownload() === true
&& auth()->check() === false) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Shaarli/Concerns/ControlsSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* @method string getName()
* @method string getLocale()
* @method bool getIsPrivate()
* @method bool getPrivateDownload()
* @method bool getIsDark()
* @method bool getHomeShowTags()
* @method bool getHomeShowChests()
* @method bool getCompactCardslist()
* @method bool getColumnsCount()
* @method string getCustomBackground()
* @method string getCustomIcon()
* @method bool getPrivateArchive()
* @method bool getLinkArchivePdf()
* @method string getNodeBin()
* @method bool getLinkArchiveMedia()
Expand Down
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

## Added

- Albums can be downloaded as .zip
- Ability to test email configuration from settings
- Robots are disabled when global privacy is enabled

## Changed

- New responsive navbar (issue #49)
- Limit displayed tags in tags card (issue #50)
- CheckArchive becames CheckFeature
- Private archive setting is now Private download
- CheckArchive is now CheckFeature

## Fixed

Expand Down
8 changes: 4 additions & 4 deletions config/shaarli.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'default' => false,
'rules' => ['nullable', 'in:on,off']
],
'private_download' => [
'default' => true,
'rules' => ['nullable', 'in:on,off']
],
'is_dark' => [
'default' => false,
'rules' => ['nullable', 'in:on,off']
Expand Down Expand Up @@ -50,10 +54,6 @@
'default' => '/images/logo-shaarli.png',
'rules' => ['nullable', 'image', 'mimes:png', 'dimensions:width=512,height=512'],
],
'private_archive' => [
'default' => false,
'rules' => ['nullable', 'in:on,off']
],
'secure_login' => [
'default' => false,
'rules' => ['nullable', 'in:on,off']
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=f127c09f6fd94d5f8565",
"/js/app.js": "/js/app.js?id=9fe6fdab96fe33b61c0c",
"/css/app.css": "/css/app.css?id=6fd92e337e2e57cee095",
"/js/manifest.js": "/js/manifest.js?id=3c768977c2574a34506e",
"/js/vendor.js": "/js/vendor.js?id=d01e65db03bef4cabb61"
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/AlbumCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" :href="album.permalink"><i class="fas fa-link fa-fw mr-1"></i> {{ __('Permalink') }}</a>
<a class="dropdown-item" :href="album.url_download" v-if="album.url_download"><i class="fas fa-file-download fa-fw mr-1"></i> {{ __('Download') }}</a>

<h6 class="dropdown-header" v-if="album.editable">{{ __('Manage') }}</h6>

Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/LinkCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" :href="link.permalink"><i class="fas fa-link fa-fw mr-1"></i> {{ __('Permalink') }}</a>
<a class="dropdown-item" :href="link.url_download" v-if="link.url_download"><i class="fas fa-file-download fa-fw mr-1"></i> {{ __('Download archive') }}</a>
<a class="dropdown-item" :href="link.url_download" v-if="link.url_download"><i class="fas fa-file-download fa-fw mr-1"></i> {{ __('Download') }}</a>

<h6 class="dropdown-header" v-if="link.editable">{{ __('Manage') }}</h6>

Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/LinkForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<h4>{{ __('Current archive') }}</h4>

<p v-if="archive.download">
<a :href="link.url_download" class="btn btn-sm btn-primary text-white btn-block">{{ __('Download archive') }}</a>
<a :href="link.url_download" class="btn btn-sm btn-primary text-white btn-block">{{ __('Download') }}</a>
<confirm class="btn btn-sm btn-danger text-white btn-block" :text="__('Delete archive')" :text-confirm="__('Confirm')" @confirmed="deleteArchive"></confirm>
</p>

Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/ManageArchives.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" :href="archive.url_download">
<i class="fas fa-file-download fa-fw mr-1"></i> {{ __('Download archive') }}
<i class="fas fa-file-download fa-fw mr-1"></i> {{ __('Download') }}
</a>
<confirm class="dropdown-item"
:text="`<i class='fas fa-trash-alt fa-fw mr-1'></i> ${__('Delete')}`"
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"Purge": "Bereinigen",
"Confirm": "Bestätigen",
"Save": "Speichern",
"Download": "Herunterladen",
"View": "Ansehen",
"Add": "Hinzufügen",
"Move": "Verschieben",
Expand Down Expand Up @@ -111,7 +112,6 @@
"Archive as PDF": "Als PDF archivieren",
"New archive": "Neues Archiv",
"Current archive": "Aktuelles Archiv",
"Download archive": "Archiv herunterladen",
"Delete archive": "Archiv löschen",
"Archive has been deleted": "Das Archiv wurde gelöscht",
"Archive does not exist": "Das Archiv existiert nicht",
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/de/shaarli.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'site_name' => 'Name der Website',
'lang' => 'Sprache',
'private_help' => 'Privater Inhalt (alle Inhalte sind privat und eine Anmeldung ist erforderlich)',
'private_download' => 'Downloads privat halten (Links und Alben)'
],

'appearance' => [
Expand All @@ -31,7 +32,6 @@

'archiving' => [
'title' => "Archivierung",
'private_archive' => "Archive als privat umstellen? ",
'link_archive_pdf' => "PDF-Archivierung (Webseiten zu PDF)",
'node_bin' => "ausführbare Node.js-Datei",
'link_archive_media' => "Archvierung der Medien (Youtube, Soundcloud, ...)",
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/shaarli.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'site_name' => 'Site name',
'lang' => 'Language',
'private_help' => 'Private content (all content is private and login is required)',
'private_download' => 'Keep downloads private (links and albums)'
],

'appearance' => [
Expand All @@ -32,7 +33,6 @@

'archiving' => [
'title' => 'Archiving',
'private_archive' => 'Make archives private?',
'link_archive_pdf' => 'PDF archiving (Web pages to PDF)',
'node_bin' => 'Node.js binary',
'link_archive_media' => 'Media archiving (Youtube, Soundcloud, ...)',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"Purge": "Purger",
"Confirm": "Confirmer",
"Save": "Enregistrer",
"Download": "Télécharger",
"View": "Voir",
"Add": "Ajouter",
"Move": "Déplacer",
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fr/shaarli.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'site_name' => 'Nom du site',
'lang' => 'Langue',
'private_help' => "Contenu privé (tout est privé et nécessite d'être connecté)",
'private_download' => 'Garder les téléchargements privés (liens et albums)'
],

'appearance' => [
Expand All @@ -31,7 +32,6 @@

'archiving' => [
'title' => "Archivage",
'private_archive' => "Rendre les archives privées ?",
'link_archive_pdf' => "Archiver les pages en PDF",
'node_bin' => "Éxécutable node.js",
'link_archive_media' => "Archiver les médias (Youtube, Soundcloud, ...)",
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"Purge": "消去",
"Confirm": "確認",
"Save": "保存",
"Download": "ダウンロード",
"View": "見る",
"Add": "追加",
"Move": "移動",
Expand Down Expand Up @@ -111,7 +112,6 @@
"Archive as PDF": "PDFとしてアーカイブする",
"New archive": "新しいアーカイブ",
"Current archive": "現在のアーカイブ",
"Download archive": "アーカイブをダウンロード",
"Delete archive": "アーカイブを削除",
"Archive has been deleted": "アーカイブが削除されました",
"Archive does not exist": "アーカイブは見つかりません",
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ja/shaarli.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'site_name' => 'サイトの名前',
'lang' => '言語',
'private_help' => '非公開(全てのコンテンツが非公開になる。コンテンツへのアクセスにログインが必要。)',
'private_download' => 'ダウンロードを非公開にしますか?(URLとアルバム)'
],

'appearance' => [
Expand All @@ -31,7 +32,6 @@

'archiving' => [
'title' => 'アーカイブ中',
'private_archive' => 'アーカイブを非公開にしますか?',
'link_archive_pdf' => 'PDFアーカイブ (サイトをPDF化)',
'node_bin' => 'Node.jsバイナリ',
'link_archive_media' => 'メディアアーカイブ (Youtube, Soundcloud, ...)',
Expand Down
19 changes: 11 additions & 8 deletions resources/views/manage/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
<span class="text-danger" role="alert">{{ $message }}</span>
@enderror
</div>

<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input"
name="private_download" id="private_download" {{ old('private_download', $settings['private_download']) ? ' checked' : '' }}>
<label class="custom-control-label" for="private_download">{{ __('shaarli.settings.general.private_download') }}</label>
</div>
@error('private_download')
<span class="text-danger" role="alert">{{ $message }}</span>
@enderror
</div>
</div>
</div>

Expand Down Expand Up @@ -156,14 +167,6 @@
</div>

<div class="card-body">
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input"
name="private_archive" id="private_archive" {{ old('private_archive', $settings['private_archive']) ? ' checked' : '' }}>
<label class="custom-control-label" for="private_archive">{{ __('shaarli.settings.archiving.private_archive') }}</label>
</div>
</div>

<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input"
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

Route::get('album/create', 'AlbumController@create')->name('album.create');
Route::get('album/{id}/edit', 'AlbumController@edit')->name('album.edit');
Route::get('album/{id}/download', 'AlbumController@download')->name('album.download');

Route::get('link/{link}', 'BrowseController@link')->name('link.view');
Route::get('story/{story}', 'BrowseController@story')->name('story.view');
Expand Down

0 comments on commit ebbf328

Please sign in to comment.