📦 Laravel 6 ♻️ Simplified Hashid 📦 TNTSearch 💩 Feeds

This commit is contained in:
MarceauKa 2019-09-03 16:48:39 +02:00
parent d43dc535bb
commit 15920cbfe0
22 changed files with 508 additions and 953 deletions

View File

@ -3,7 +3,6 @@
namespace App;
use App\Concerns\Models\Postable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class Chest extends Model
@ -19,21 +18,11 @@ class Chest extends Model
'content' => 'json',
];
public function getHashIdAttribute(): string
{
return hashid_encode($this->id);
}
public function getPermalinkAttribute(): string
{
return route('chest.view', $this->hash_id);
}
public function scopeHashIdIs(Builder $query, string $hash): Builder
{
return $query->where('id', hashid_decode($hash));
}
public function toSearchableArray()
{
return [

View File

@ -75,6 +75,7 @@ class Kernel extends HttpKernel
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\Authenticate::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,

View File

@ -7,11 +7,8 @@ use App\Services\LinkPreview\LinkPreview;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;
class Link extends Model implements Feedable
class Link extends Model
{
use Postable;
@ -28,7 +25,7 @@ class Link extends Model implements Feedable
public function getHashIdAttribute(): string
{
return hashid_encode($this->id);
return app('hashid')->encode($this->id);
}
public function getPermalinkAttribute(): string
@ -47,7 +44,7 @@ class Link extends Model implements Feedable
public function scopeHashIdIs(Builder $query, string $hash): Builder
{
return $query->where('id', hashid_decode($hash));
return $query->where('id', app('hashid')->decode($hash));
}
public function updatePreview(): self
@ -85,21 +82,4 @@ class Link extends Model implements Feedable
return true;
}
public function toFeedItem()
{
return FeedItem::create([
'id' => $this->id,
'title' => $this->title,
'summary' => Str::limit($this->content, 130) ?? 'N.C',
'updated' => $this->updated_at,
'link' => $this->permalink,
'author' => config('app.name'),
]);
}
public static function getFeedItems()
{
return Link::latest()->withPrivate(false)->get();
}
}

View File

@ -2,6 +2,7 @@
namespace App\Providers;
use App\Services\Hashid;
use App\Services\Shaarli\Shaarli;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
@ -19,6 +20,12 @@ class AppServiceProvider extends ServiceProvider
});
$this->app->alias(Shaarli::class, 'shaarli');
$this->app->singleton(Hashid::class, function ($app) {
return new Hashid($app['config']->get('shaarli.hashids'));
});
$this->app->alias(Hashid::class, 'hashid');
}
public function boot()

28
app/Services/Hashid.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace App\Services;
use Hashids\Hashids;
class Hashid
{
protected $hashids;
public function __construct(array $config = [])
{
$this->hashids = new Hashids(
$config['salt'],
$config['min'],
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
);
}
public function encode($data): string
{
return $this->hashids->encode($data);
}
public function decode($data)
{
return $this->hashids->decode($data);
}
}

View File

@ -15,7 +15,7 @@ use Spatie\Valuestore\Valuestore;
class Shaarli
{
/** @var string VERSION */
public const VERSION = '1.1.1';
public const VERSION = '1.2.0';
/** @var Application $app */
protected $app;
/** @var Valuestore $settings */

View File

@ -6,10 +6,8 @@ use App\Concerns\Models\Postable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;
class Story extends Model implements Feedable
class Story extends Model
{
use Postable;
@ -34,21 +32,4 @@ class Story extends Model implements Feedable
{
return $query->where('slug', $slug);
}
public function toFeedItem()
{
return FeedItem::create([
'id' => $this->id,
'title' => $this->title,
'summary' => Str::limit($this->content, 130) ?? 'N.C',
'updated' => $this->updated_at,
'link' => $this->url,
'author' => config('app.name'),
]);
}
public static function getFeedItems()
{
return Story::latest()->withPrivate(false)->get();
}
}

View File

@ -1,4 +1,4 @@
# Unreleased
# 1.2.0
## Added
@ -6,6 +6,15 @@
- Add original URL to card-link
- Ability to "Save and archive" a link
## Changed
- Laravel 6.0
- Simplified Hashid
## Deleted
- Feeds
# 1.1.1
## Fixed

View File

@ -9,29 +9,27 @@
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"php": "^7.2",
"doctrine/dbal": "^2.9",
"elfsundae/laravel-hashid": "^1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/framework": "^6.0",
"laravel/scout": "^7.1",
"laravel/tinker": "^1.0",
"maatwebsite/excel": "^3.1",
"nesk/puphpeteer": "^1.6",
"norkunas/youtube-dl-php": "^1.3",
"predis/predis": "^1.1",
"spatie/laravel-feed": "^2.3",
"spatie/valuestore": "^1.2",
"teamtnt/laravel-scout-tntsearch-driver": "^7.1"
"hashids/hashids": "^2.0.4|~3.0",
"marceauka/laravel-scout-tntsearch-driver": "^7.2"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"laravel/dusk": "^5.5",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^8.0"
},
"config": {
"optimize-autoloader": true,

1266
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +0,0 @@
<?php
return [
'feeds' => [
'main' => [
'items' => 'App\\Link::getFeedItems',
'url' => '/feed',
'title' => env('APP_NAME'),
'view' => 'feed::feed',
],
],
];

View File

@ -1,13 +0,0 @@
<?php
return [
'default' => env('HASHID_CONNECTION', 'hashids'),
'connections' => [
'hashids' => [
'driver' => 'hashids',
'salt' => env('HASHIDS_SALT', ''),
'min_length' => env('HASHIDS_MIN_LENGTH', 0),
'alphabet' => env('HASHIDS_ALPHABET', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'),
],
],
];

View File

@ -1,7 +1,7 @@
<?php
return [
// Supported: "smtp", "sendmail", "mandrill", "ses",
// Supported: "smtp", "sendmail", "ses",
// "postmark", "log", "array"
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

View File

@ -37,6 +37,7 @@ return [
],
],
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],

View File

@ -10,4 +10,8 @@ return [
'link_archive_media' => true,
'node_bin' => '/usr/bin/node',
'youtube_dl_bin' => '/usr/bin/youtube-dl',
'hashids' => [
'salt' => env('HASHIDS_SALT', 'default-salt'),
'min' => env('HASHIDS_MIN_LENGTH', 10),
],
];

View File

@ -25,9 +25,12 @@ but built with [Laravel](https://github.com/laravel/laravel) and [Vue.js](https:
## Requirements
- PHP >= 7.1
- Apache or nginx
- MySQL >= 5.7 or SQLite >= 3
- Linux or macOS env
- PHP >= 7.2
- MySQL >= 5.7 (or SQLite >= 3)
- Node.js >= 6
- (Optional) Redis
- (Optional) [youtube-dl](https://github.com/ytdl-org/youtube-dl)
## Features

View File

@ -165,6 +165,5 @@
"Export type or format not recognized": "Type d'export ou format non-reconnu",
"Source code": "Code source",
"RSS Feed": "Flux RSS"
"Source code": "Code source"
}

View File

@ -1,7 +1,6 @@
<footer>
<p class="text-center">
{{ app('shaarli')->getName() }} - v{{ app('shaarli')::VERSION }} -
<a href="{{ route('feeds.main') }}">{{ __('RSS Feed') }}</a> -
<a href="https://github.com/MarceauKa/laravel-shaarli">{{ __('Source code') }}</a>
</p>
</footer>

View File

@ -6,7 +6,6 @@
<meta name="api-token" content="{{ auth()->user()->api_token }}">
@endif
@stack('meta')
@include('feed::links')
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<link href="{{ mix('css/app.css') }}" rel="stylesheet">

View File

@ -36,7 +36,7 @@
<table class="table table-condensed table-bordered">
@if(in_array('media', $providers))
<tr>
<td>{{ __('Archive media') }}</td>
<td>{{ __('Archive as Media') }}</td>
<td class="text-right">
<button type="submit" class="btn btn-sm btn-primary btn-block" name="type" value="media">{{ __('Choose') }}</button>
</td>
@ -45,7 +45,7 @@
@if(in_array('pdf', $providers))
<tr>
<td>{{ __('Archive PDF') }}</td>
<td>{{ __('Archive as PDF') }}</td>
<td class="text-right">
<button type="submit" class="btn btn-sm btn-primary btn-block" name="type" value="pdf">{{ __('Choose') }}</button>
</td>

View File

@ -8,8 +8,6 @@ Route::auth([
'verify' => false,
]);
Route::feeds();
Route::get('/', 'BrowseController@index')->name('home');
Route::get('/tag/{tag}', 'BrowseController@tag')->name('tag');

22
tests/boostrap.php Normal file
View File

@ -0,0 +1,22 @@
<?php
use Illuminate\Contracts\Console\Kernel;
require_once __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Bootstrap The Test Environment
|--------------------------------------------------------------------------
|
| You may specify console commands that execute once before your test is
| run. You are free to add your own additional commands or logic into
| this file as needed in order to help your test suite run quicker.
|
*/
$commands = [
'config:cache',
'event:cache',
];
$app = require __DIR__.'/../bootstrap/app.php';
$console = tap($app->make(Kernel::class))->bootstrap();
foreach ($commands as $command) {
$console->call($command);
}