Skip to content

Commit

Permalink
Merge pull request #486 from Kovah/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Kovah authored Jun 10, 2022
2 parents 80a8a1b + f6d2ea0 commit 68c2292
Show file tree
Hide file tree
Showing 26 changed files with 1,651 additions and 1,878 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ _ide_*
/.git
/.idea
/.tmp
/storage/app/backup-temp
/storage/app/backups
/storage/app/backups/*
/storage/debugbar/*
/storage/framework/cache/*
/storage/framework/sessions/*
Expand Down
6 changes: 5 additions & 1 deletion app/Console/Commands/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public function handle(): void
if ($this->option('skip-check')) {
$this->info('Skipping link check.');
} else {
Artisan::queue('links:check');
if (config('mail.host') !== null) {
Artisan::queue('links:check');
} else {
$this->warn('Links are configured to be checked, but email is not configured!');
}
}

$this->info(trans('import.import_successfully', [
Expand Down
14 changes: 10 additions & 4 deletions app/Helper/WaybackMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

class WaybackMachine
{
/** @var string */
public static $baseUrl = 'https://web.archive.org';
public static string $baseUrl = 'https://web.archive.org';

/**
* Save an URL to the Wayback Machine
Expand All @@ -25,12 +24,19 @@ public static function saveToArchive(string $url): bool

$archiveUrl = self::$baseUrl . '/save/' . $url;

$request = Http::timeout(10);
$request = Http::timeout(1);
if (config('html-meta.user_agents', false)) {
$agents = config('html-meta.user_agents');
$request->withHeaders(['User-Agent' => $agents[array_rand($agents)]]);
}
$response = $request->head($archiveUrl);
try {
$response = $request->head($archiveUrl);
} catch (\Exception $e) {
if (!str_contains($e->getMessage(), 'cURL error 28: Operation timed out')) {
Log::warning($archiveUrl . ': ' . $e->getMessage());
}
return false;
}

try {
$response->throw();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LinkController extends Controller
*/
public function index(Request $request): JsonResponse
{
$links = Link::byUser(auth()->id())
$links = Link::byUser()
->orderBy(
$request->input('order_by', 'created_at'),
$request->input('order_dir', 'DESC')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ListController extends Controller
*/
public function index(Request $request): JsonResponse
{
$lists = LinkList::byUser(auth()->id())
$lists = LinkList::byUser()
->orderBy(
$request->input('order_by', 'created_at'),
$request->input('order_dir', 'DESC')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TagController extends Controller
*/
public function index(Request $request): JsonResponse
{
$tags = Tag::byUser(auth()->id())
$tags = Tag::byUser()
->orderBy(
$request->input('order_by', 'created_at'),
$request->input('order_dir', 'DESC')
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/App/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ class DashboardController extends Controller
*/
public function index(): View
{
$recentLinks = Link::byUser(auth()->user()->id)
$recentLinks = Link::byUser()
->latest()
->limit(5)
->get();

$recentTags = Tag::byUser(auth()->user()->id)
$recentTags = Tag::byUser()
->latest()
->limit(25)
->get();

$recentLists = LinkList::byUser(auth()->user()->id)
$recentLists = LinkList::byUser()
->latest()
->limit(15)
->get();

$brokenLinks = Link::byUser(auth()->user()->id)
$brokenLinks = Link::byUser()
->where('status', '>', 1)
->count();

Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/App/TrashController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ class TrashController extends Controller
public function index(): View
{
$links = Link::onlyTrashed()
->byUser(auth()->id())
->byUser()
->get();

$lists = LinkList::onlyTrashed()
->byUser(auth()->id())
->byUser()
->get();

$tags = Tag::onlyTrashed()
->byUser(auth()->id())
->byUser()
->get();

$notes = Note::onlyTrashed()
->byUser(auth()->id())
->byUser()
->get();

return view('app.trash.index', [
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/FetchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getTags(Request $request): JsonResponse
return response()->json([]);
}

$tags = Tag::byUser(auth()->user()->id)
$tags = Tag::byUser()
->where('name', 'like', '%' . escapeSearchQuery($query) . '%')
->orderBy('name')
->get();
Expand Down Expand Up @@ -59,7 +59,7 @@ public function getLists(Request $request): JsonResponse
return response()->json([]);
}

$tags = LinkList::byUser(auth()->user()->id)
$tags = LinkList::byUser()
->where('name', 'like', '%' . escapeSearchQuery($query) . '%')
->orderBy('name')
->get();
Expand Down Expand Up @@ -92,7 +92,7 @@ public function searchExistingUrls(Request $request): JsonResponse
return response()->json([]);
}

$link = Link::byUser(auth()->user()->id)
$link = Link::byUser()
->where('url', trim($query))
->where('id', '!=', $request->input('ignore_id', 0))
->first();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Models/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function index(Request $request): View
session()->put('links.index.orderBy', $orderBy);
session()->put('links.index.orderDir', $orderDir);

$links = Link::byUser(auth()->id())
$links = Link::byUser()
->with('tags')
->orderBy($orderBy, $orderDir)
->paginate(getPaginationLimit());
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Models/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function index(Request $request): View
session()->put('lists.index.orderBy', $orderBy);
session()->put('lists.index.orderDir', $orderDir);

$lists = LinkList::byUser(auth()->id())
$lists = LinkList::byUser()
->withCount('links')
->orderBy($orderBy, $orderDir);

Expand Down Expand Up @@ -88,7 +88,7 @@ public function store(ListStoreRequest $request): RedirectResponse
public function show(Request $request, LinkList $list): View
{
$links = $list->links()
->byUser(auth()->id())
->byUser()
->orderBy(
$request->input('orderBy', 'created_at'),
$request->input('orderDir', 'desc')
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Models/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function index(Request $request): View
session()->put('tags.index.orderBy', $orderBy);
session()->put('tags.index.orderDir', $orderDir);

$tags = Tag::byUser(auth()->id())
$tags = Tag::byUser()
->withCount('links')
->orderBy($orderBy, $orderDir);

Expand Down Expand Up @@ -88,7 +88,7 @@ public function store(TagStoreRequest $request): RedirectResponse
*/
public function show(Request $request, Tag $tag): View
{
$links = $tag->links()->byUser(auth()->id())
$links = $tag->links()->byUser()
->orderBy(
$request->input('orderBy', 'created_at'),
$request->input('orderDir', 'desc')
Expand Down
64 changes: 31 additions & 33 deletions app/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @property Collection|Revision[] $revisionHistory
* @property Collection|Tag[] $tags
* @property User $user
* @method static Builder|Link byUser($user_id)
* @method static Builder|Link byUser($user_id = null)
* @method static Builder|Link privateOnly()
* @method static Builder|Link publicOnly()
* @method static MorphMany revisionHistory()
Expand All @@ -49,8 +49,18 @@ class Link extends Model
use RevisionableTrait;
use HasFactory;

public const STATUS_OK = 1;
public const STATUS_MOVED = 2;
public const STATUS_BROKEN = 3;
public const DISPLAY_CARDS = 1;
public const DISPLAY_CARDS_DETAILED = 3;
public const DISPLAY_LIST_SIMPLE = 2;
public const DISPLAY_LIST_DETAILED = 0;
public const REV_TAGS_NAME = 'revtags';
public const REV_LISTS_NAME = 'revlists';
public $table = 'links';

// Revisions settings
public $fillable = [
'user_id',
'url',
Expand All @@ -62,31 +72,16 @@ class Link extends Model
'check_disabled',
'thumbnail',
];

protected $casts = [
'user_id' => 'integer',
'is_private' => 'boolean',
'status' => 'integer',
'check_disabled' => 'boolean',
];

public const STATUS_OK = 1;
public const STATUS_MOVED = 2;
public const STATUS_BROKEN = 3;

public const DISPLAY_CARDS = 1;
public const DISPLAY_CARDS_DETAILED = 3;
public const DISPLAY_LIST_SIMPLE = 2;
public const DISPLAY_LIST_DETAILED = 0;

// Revisions settings
protected $revisionCleanup = true;
protected $historyLimit = 50;
protected $dontKeepRevisionOf = ['icon'];

public const REV_TAGS_NAME = 'revtags';
public const REV_LISTS_NAME = 'revlists';


/*
| ========================================================================
Expand All @@ -96,13 +91,16 @@ class Link extends Model
/**
* Scope for the user relation
*
* @param Builder $query
* @param int $userId
* @param Builder $query
* @param int|null $user_id
* @return Builder
*/
public function scopeByUser(Builder $query, int $userId): Builder
public function scopeByUser(Builder $query, int $user_id = null): Builder
{
return $query->where('user_id', $userId);
if (is_null($user_id) && auth()->check()) {
$user_id = auth()->id();
}
return $query->where('user_id', $user_id);
}

/**
Expand Down Expand Up @@ -187,19 +185,6 @@ public function getFormattedDescriptionAttribute(): string
return Str::markdown($this->description, ['html_input' => 'escape']);
}

/**
* Get the URL shortened to max 50 characters and with https:// removed.
* Other protocols like magnet://, ftp:// and so on will be kept to make
* those protocols more obvious for the user.
*
* @param int $maxLength
* @return string
*/
public function shortUrl(int $maxLength = 50): string
{
return preg_replace('/http(s)?:\/\//', '', Str::limit(trim($this->url, '/'), $maxLength));
}

/**
* Get the title shortened to max 50 characters
*
Expand All @@ -222,6 +207,19 @@ public function domainOfURL(): string
return $urlDetails['host'] ?? $this->shortUrl(20);
}

/**
* Get the URL shortened to max 50 characters and with https:// removed.
* Other protocols like magnet://, ftp:// and so on will be kept to make
* those protocols more obvious for the user.
*
* @param int $maxLength
* @return string
*/
public function shortUrl(int $maxLength = 50): string
{
return preg_replace('/http(s)?:\/\//', '', Str::limit(trim($this->url, '/'), $maxLength));
}

public function tagsForInput(): ?string
{
$tags = $this->tags;
Expand Down
Loading

0 comments on commit 68c2292

Please sign in to comment.