1
0
Fork 0

Merge pull request #1046 from pixelfed/frontend-ui-refactor

Instagram Import
This commit is contained in:
daniel 2019-03-18 21:14:09 -06:00 committed by GitHub
commit f2cadd136f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 10 deletions

View File

@ -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());
}
}

View File

@ -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');
}
}
}

View File

@ -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();

View File

@ -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)
]
]
],
];