diff --git a/app/Http/Controllers/Import/Instagram.php b/app/Http/Controllers/Import/Instagram.php index 401a6be38..0b1486f31 100644 --- a/app/Http/Controllers/Import/Instagram.php +++ b/app/Http/Controllers/Import/Instagram.php @@ -11,6 +11,7 @@ use App\{ Profile, User }; +use App\Jobs\ImportPipeline\ImportInstagram; trait Instagram { @@ -21,6 +22,13 @@ trait Instagram public function instagramStart(Request $request) { + $completed = ImportJob::whereProfileId(Auth::user()->profile->id) + ->whereService('instagram') + ->whereNotNull('completed_at') + ->exists(); + if($completed == true) { + return redirect(route('settings'))->with(['errors' => ['You can only import from Instagram once.']]); + } $job = $this->instagramRedirectOrNew(); return redirect($job->url()); } @@ -134,8 +142,6 @@ trait Instagram $job->stage = 3; $job->save(); return redirect($job->url()); - return $json; - } public function instagramStepThree(Request $request, $uuid) @@ -148,4 +154,19 @@ trait Instagram ->firstOrFail(); return view('settings.import.instagram.step-three', compact('profile', 'job')); } + + public function instagramStepThreeStore(Request $request, $uuid) + { + $profile = Auth::user()->profile; + + $job = ImportJob::whereProfileId($profile->id) + ->whereNull('completed_at') + ->whereUuid($uuid) + ->whereStage(3) + ->firstOrFail(); + + ImportInstagram::dispatchNow($job); + + return redirect($profile->url()); + } } diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index ba99900bc..6598a9e7c 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -11,6 +11,10 @@ class ImportController extends Controller public function __construct() { $this->middleware('auth'); + + if(config('pixelfed.import.instagram.enabled') != true) { + abort(404, 'Feature not enabled'); + } } } diff --git a/app/Jobs/ImportPipeline/ImportInstagram.php b/app/Jobs/ImportPipeline/ImportInstagram.php index c6cbd9d93..1209ecd87 100644 --- a/app/Jobs/ImportPipeline/ImportInstagram.php +++ b/app/Jobs/ImportPipeline/ImportInstagram.php @@ -24,7 +24,7 @@ class ImportInstagram implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - protected $job; + protected $import; /** * Delete the job if its models no longer exist. @@ -38,9 +38,9 @@ class ImportInstagram implements ShouldQueue * * @return void */ - public function __construct(ImportJob $job) + public function __construct(ImportJob $import) { - $this->job = $job; + $this->import = $import; } /** @@ -50,8 +50,12 @@ class ImportInstagram implements ShouldQueue */ public function handle() { - $job = $this->job; - $profile = $this->job->profile; + if(config('pixelfed.import.instagram.enabled') != true) { + return; + } + + $job = ImportJob::findOrFail($this->import->id); + $profile = Profile::findOrFail($job->profile_id); $json = $job->mediaJson(); $collection = $json['photos']; $files = $job->files; @@ -74,9 +78,9 @@ class ImportInstagram implements ShouldQueue $filename = last( explode('/', $import['path']) ); $importData = ImportData::whereJobId($job->id) ->whereOriginalName($filename) - ->firstOrFail(); + ->first(); - if(is_file(storage_path("app/$importData->path")) == false) { + if(empty($importData) || is_file(storage_path("app/$importData->path")) == false) { continue; } @@ -88,6 +92,8 @@ class ImportInstagram implements ShouldQueue $status->profile_id = $profile->id; $status->caption = strip_tags($caption); $status->is_nsfw = false; + $status->type = 'photo'; + $status->scope = 'unlisted'; $status->visibility = 'unlisted'; $status->created_at = $taken_at; $status->save(); diff --git a/config/pixelfed.php b/config/pixelfed.php index 295ae058a..a5323a467 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -263,5 +263,15 @@ return [ 'ap_inbox' => env('ACTIVITYPUB_INBOX', false), 'ap_shared' => env('ACTIVITYPUB_SHAREDINBOX', false), 'ap_delivery_timeout' => env('ACTIVITYPUB_DELIVERY_TIMEOUT', 2.0), - 'ap_delivery_concurrency' => env('ACTIVITYPUB_DELIVERY_CONCURRENCY', 10) + 'ap_delivery_concurrency' => env('ACTIVITYPUB_DELIVERY_CONCURRENCY', 10), + + 'import' => [ + 'instagram' => [ + 'enabled' => env('IMPORT_INSTAGRAM_ENABLED', false), + 'limits' => [ + 'posts' => (int) env('IMPORT_INSTAGRAM_POST_LIMIT', 100), + 'size' => (int) env('IMPORT_INSTAGRAM_SIZE_LIMIT', 250) + ] + ] + ], ];