-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Ability to test PDF and Media archiving in settings (issue #34)
- Loading branch information
Showing
9 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\Manage; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Services\LinkArchive\LinkArchive; | ||
use App\Services\LinkArchive\YoutubeDlProvider; | ||
use App\Services\Shaarli\Shaarli; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class ArchiveController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('demo'); | ||
} | ||
|
||
public function check(Request $request, Shaarli $shaarli, string $type) | ||
{ | ||
if (false === in_array($type, ['pdf', 'media'])) { | ||
abort(404); | ||
} | ||
|
||
if ($type === 'pdf') { | ||
if (false === $shaarli->getLinkArchivePdf()) { | ||
return $this->sendError(__('Archive as PDF is not enabled')); | ||
} | ||
|
||
$exec = $shaarli->getNodeBin(); | ||
exec($exec . ' --version', $result); | ||
|
||
if (empty($result)) { | ||
return $this->sendError(__('Your node path is unreachable: :path', ['path' => $exec])); | ||
} | ||
|
||
$dir = base_path('node_modules/puppeteer/.local-chromium'); | ||
|
||
if (false === is_dir($dir)) { | ||
return $this->sendError(__('Puppeteer dependencies not installed, run `npm install @nesk/puphpeteer --no-save`')); | ||
} | ||
|
||
try { | ||
$name = LinkArchive::archive(url()->route('home'), 'pdf'); | ||
} catch (\Exception $e) { | ||
return $this->sendError(__('Unable to create archive, error is: :message', ['message' => $e->getMessage()])); | ||
} | ||
|
||
Storage::disk('archives')->delete($name); | ||
} | ||
|
||
if ($type === 'media') { | ||
if (false === $shaarli->getLinkArchiveMedia()) { | ||
return $this->sendError(__('Archive as Media is not enabled')); | ||
} | ||
|
||
$exec = $shaarli->getYoutubeDlBin(); | ||
exec($exec . ' --version', $result); | ||
|
||
if (empty($result)) { | ||
return $this->sendError(__('Your youtube-dl path is unreachable: :path', ['path' => $exec])); | ||
} | ||
|
||
$status = YoutubeDlProvider::test('https://www.youtube.com/watch?v=oavMtUWDBTM'); | ||
|
||
if ($status === false) { | ||
return $this->sendError(__("Unknow error. Check if python is correctly installed on your system")); | ||
} | ||
} | ||
|
||
return response()->json([ | ||
'status' => 'success', | ||
]); | ||
} | ||
|
||
protected function sendError(string $message): JsonResponse | ||
{ | ||
return response()->json([ | ||
'status' => 'fail', | ||
'message' => $message | ||
], 422); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<template> | ||
<button type="button" | ||
class="btn btn-primary" | ||
:class="{'btn-danger': status === 'fail', 'btn-success': status === 'success'}" | ||
@click="check" | ||
:disabled="loading" | ||
> | ||
<span v-if="!loading && status === null">{{ __('Check') }}</span> | ||
<span v-else-if="status === 'success'">{{ __('Success') }}</span> | ||
<span v-else-if="status === 'fail'">{{ __('Fail') }}</span> | ||
<span v-else> | ||
<div class="spinner-grow spinner-grow-sm" role="status"></div> | ||
</span> | ||
</button> | ||
</template> | ||
|
||
<script> | ||
import httpErrors from "../mixins/httpErrors"; | ||
export default { | ||
mixins: [ | ||
httpErrors, | ||
], | ||
props: { | ||
type: { | ||
type: String, | ||
required: true | ||
}, | ||
}, | ||
data() { | ||
return { | ||
loading: false, | ||
status: null, | ||
} | ||
}, | ||
methods: { | ||
check() { | ||
this.loading = true; | ||
axios.get(`/api/manage/archive/check/${this.type}`) | ||
.then(response => { | ||
this.status = response.data.status; | ||
this.clear(); | ||
}) | ||
.catch(error => { | ||
this.status = 'fail'; | ||
this.setHttpError(error); | ||
this.toastHttpError(this.__('Whoops!')); | ||
this.clear(); | ||
}) | ||
}, | ||
clear() { | ||
this.loading = false; | ||
setTimeout(() => { | ||
this.status = null; | ||
}, 5000); | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters