Initial Commit
linter / quality (push) Canceled after 0s
tests / ci (8.3) (push) Canceled after 0s
tests / ci (8.4) (push) Canceled after 0s
tests / ci (8.5) (push) Canceled after 0s

This commit is contained in:
2026-08-29 00:17:41 +10:00
parent 37ff8e0a88
commit b2f2d8b104
13 changed files with 378 additions and 35 deletions
+31 -16
View File
@@ -3,6 +3,7 @@
namespace App\Console\Commands;
use App\Models\Story;
use App\Services\StoryMediaCacher;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
@@ -21,25 +22,39 @@ class ScrapeStories extends RunsPlaywrightScript
return;
}
$mediaCacher = app(StoryMediaCacher::class);
$items = json_decode(file_get_contents($path), true);
foreach ($items as $item) {
Story::updateOrCreate(
['id' => $item['id']],
[
'user_id' => $item['user_id'],
'username' => $item['username'],
'profile_pic_url' => $item['profile_pic_url'],
'code' => $item['code'],
'is_video' => $item['is_video'],
'taken_at' => $item['taken_at'],
'expiring_at' => $item['expiring_at'],
'image_url' => $item['image_url'],
'video_url' => $item['video_url'],
'accessibility_caption' => $item['accessibility_caption'],
'muted' => $item['muted'],
]
);
$attributes = [
'user_id' => $item['user_id'],
'username' => $item['username'],
'profile_pic_url' => $item['profile_pic_url'],
'code' => $item['code'],
'is_video' => $item['is_video'],
'taken_at' => $item['taken_at'],
'expiring_at' => $item['expiring_at'],
'image_url' => $item['image_url'],
'video_url' => $item['video_url'],
'accessibility_caption' => $item['accessibility_caption'],
'muted' => $item['muted'],
];
$existing = Story::find($item['id']);
// Once a story's media has been cached locally, its url columns
// no longer point at Instagram — don't let a re-scrape clobber
// them with a freshly (and just as temporarily) signed CDN url.
if ($existing) {
if (! $mediaCacher->isInstagramUrl($existing->image_url)) {
unset($attributes['image_url']);
}
if (! $mediaCacher->isInstagramUrl($existing->video_url)) {
unset($attributes['video_url']);
}
}
Story::updateOrCreate(['id' => $item['id']], $attributes);
}
$this->info('Upserted ' . count($items) . ' story items.');