1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-01-17 21:28:30 +01:00

Add default date for imported bookmarks if there's no date in the export (#752)

This commit is contained in:
Kovah 2024-02-20 10:45:19 +01:00
parent 54f537f047
commit ada6d5ed3f
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
3 changed files with 60 additions and 5 deletions

View File

@ -6,7 +6,7 @@ use App\Helper\HtmlMeta;
use App\Helper\LinkIconMapper;
use App\Models\Link;
use App\Models\Tag;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
@ -20,7 +20,7 @@ class ImportHtmlBookmarks
*
* @param string $data
* @param string $userId
* @param bool $generateMeta
* @param bool $generateMeta
* @return bool
*/
public function run(string $data, string $userId, bool $generateMeta = true): bool
@ -64,7 +64,9 @@ class ImportHtmlBookmarks
'icon' => LinkIconMapper::mapLink($link['url']),
'is_private' => usersettings('tags_private_default') === '1' ? true : $isPublic,
]);
$newLink->created_at = Carbon::createFromTimestamp($link['dateCreated']);
$newLink->created_at = $link['dateCreated']
? Carbon::createFromTimestamp($link['dateCreated'])
: Carbon::now();
$newLink->updated_at = Carbon::now();
$newLink->timestamps = false;
$newLink->save();

View File

@ -6,6 +6,7 @@ use App\Models\Setting;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Testing\TestResponse;
use Tests\TestCase;
@ -44,6 +45,25 @@ class ImportControllerTest extends TestCase
$this->assertDatabaseCount('tags', 18);
}
public function testDatelessImportActionResponse(): void
{
$this->travelTo(Carbon::create(2024, 2, 20));
$response = $this->importBookmarks('/data/import_example_dateless.html');
$response->assertOk()
->assertJson([
'success' => true,
]);
$this->assertDatabaseCount('links', 5);
$this->assertDatabaseCount('tags', 18);
$this->assertDatabaseHas('links', [
'url' => 'https://loader.io/',
'created_at' => '2024-02-20 00:00:00'
]);
}
public function testImportWithPrivateDefaults(): void
{
Setting::create(['user_id' => 1, 'key' => 'links_private_default', 'value' => '1']);
@ -69,12 +89,12 @@ class ImportControllerTest extends TestCase
]);
}
protected function importBookmarks(): TestResponse
protected function importBookmarks(string $importFile = '/data/import_example.html'): TestResponse
{
$testHtml = '<!DOCTYPE html><head><title>DuckDuckGo</title></head></html>';
Http::fake(['*' => Http::response($testHtml)]);
$exampleData = file_get_contents(__DIR__ . '/data/import_example.html');
$exampleData = file_get_contents(__DIR__ . $importFile);
$file = UploadedFile::fake()->createWithContent('import_example.html', $exampleData);
return $this->post('import', [

View File

@ -0,0 +1,33 @@
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<!-- This is an automatically generated file.
It will be read and overwritten.
Do Not Edit! -->
<TITLE>LinkAce</TITLE>
<DL>
<p>
<DT>
<A
HREF="https://medium.com/accelerated-intelligence/the-5-hour-rule-if-youre-not-spending-5-hours-per-week-learning-you-re-being-irresponsible-791c3f18f5e6" PRIVATE="1" TAGS="article,intelligence">5-Hour Rule: If youre not spending 5 hours per
week learning, youre being irresponsible</A>
<DD>Why did the busiest person in the world, former president Barack Obama, read an hour a day while in office? Why
has the best investor in history, Warren Buffett, invested 80% of his time in reading…
<DT>
<A HREF="https://adele.uxpin.com/" PRIVATE="0"
TAGS="collection,design,design-systems,library,patterns">Adele Design Systems and Pattern Libraries
Repository</A>
<DT>
<A HREF="https://color.adobe.com/create/color-wheel/" PRIVATE="0"
TAGS="color-palettes,color-picker,color-wheel,colors">Adobe Color CC</A>
<DT>
<A HREF="https://loader.io/" PRIVATE="0"
TAGS="load-testing,testing,website,website-testing">Application Load Testing Tools for API Endpoints with
loader.io</A>
<DD>Free tool for web application load testing that allows for the simulation of concurrent connections to your web
application&amp;#39;s APIs
<DT>
<A HREF="https://astralapp.com/" TAGS="favourites,Github,organization">Astral —
Organize Your GitHub Stars With Ease</A>
<DD>Astral is the best way to manage your starred repositories on GitHub using tags, notes and a powerful search
feature.
</DL>