Fix support for ownyourgram, hopefully
This commit is contained in:
parent
2cd8a2c110
commit
2d7aee25c6
6 changed files with 112 additions and 2 deletions
|
@ -87,6 +87,7 @@ class MicropubController extends Controller
|
|||
//create checkin place
|
||||
if (array_key_exists('checkin', $request->input('properties'))) {
|
||||
$data['checkin'] = $request->input('properties.checkin.0.properties.url.0');
|
||||
$data['swarm-url'] = $request->input('properties.syndication.0');
|
||||
try {
|
||||
$this->placeService->createPlaceFromCheckin($request->input('properties.checkin.0'));
|
||||
} catch (\Exception $e) {
|
||||
|
@ -143,6 +144,9 @@ class MicropubController extends Controller
|
|||
$data['photo'][] = $photo;
|
||||
}
|
||||
}
|
||||
if (starts_with($request->input('properties.syndication.0'), 'https://www.instagram.com')) {
|
||||
$data['instagram-url'] = $request->input('properties.syndication.0');
|
||||
}
|
||||
}
|
||||
try {
|
||||
$note = $this->noteService->createNote($data);
|
||||
|
|
|
@ -13,6 +13,13 @@ class Media extends Model
|
|||
*/
|
||||
protected $table = 'media_endpoint';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['path'];
|
||||
|
||||
/**
|
||||
* Get the note that owns this media.
|
||||
*/
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Log;
|
||||
use App\{Media, Note, Place};
|
||||
use App\Jobs\{SendWebMentions, SyndicateToFacebook, SyndicateToTwitter};
|
||||
|
||||
|
@ -17,6 +17,7 @@ class NoteService
|
|||
*/
|
||||
public function createNote(array $data): Note
|
||||
{
|
||||
Log::info($data);
|
||||
//check the input
|
||||
if (array_key_exists('content', $data) === false) {
|
||||
throw new \Exception('No content defined'); //we can’t fudge the data
|
||||
|
@ -63,6 +64,7 @@ class NoteService
|
|||
$place = Place::where('foursquare', $data['checkin'])->first();
|
||||
if ($place !== null) {
|
||||
$note->place()->associate($place);
|
||||
$note->swarm_url = $data['swarm-url'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,12 +86,15 @@ class NoteService
|
|||
$media = Media::where('path', ltrim($path, '/'))->firstOrFail();
|
||||
} else {
|
||||
$media = Media::firstOrNew(['path' => $photo]);
|
||||
// currently assuming this is a photo from Swarm
|
||||
// currently assuming this is a photo from Swarm or OwnYourGram
|
||||
$media->type = 'image';
|
||||
$media->save();
|
||||
}
|
||||
$note->media()->save($media);
|
||||
}
|
||||
if (array_key_exists('instagram-url', $data)) {
|
||||
$note->instagram_url = $data['instagram-url'];
|
||||
}
|
||||
}
|
||||
|
||||
$note->save();
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class UpdateNotesTableAddInstagramUrl extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('notes', function (Blueprint $table) {
|
||||
$table->string('instagram_url')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('notes', function (Blueprint $table) {
|
||||
$table->dropColumn('instagram_url');
|
||||
});
|
||||
}
|
||||
}
|
59
tests/Feature/OwnYourGramTest.php
Normal file
59
tests/Feature/OwnYourGramTest.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class OwnYourGramTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_ownyourgram_post()
|
||||
{
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'/api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'content' => ['How beautiful are the plates and chopsticks'],
|
||||
'published' => [\Carbon\Carbon::now()->toIso8601String()],
|
||||
'location' => ['geo:53.802419075834,-1.5431942917637'],
|
||||
'syndication' => ['https://www.instagram.com/p/BVC_nVTBFfi/'],
|
||||
'photo' => ['https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
|
||||
$response->assertStatus(201)->assertJson([
|
||||
'response' => 'created'
|
||||
]);
|
||||
$this->assertDatabaseHas('media_endpoint', [
|
||||
'path' => 'https://scontent-sjc2-1.cdninstagram.com/t51.2885-15/e35/18888604_425332491185600_326487281944756224_n.jpg'
|
||||
]);
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'note' => 'How beautiful are the plates and chopsticks',
|
||||
'instagram_url' => 'https://www.instagram.com/p/BVC_nVTBFfi/'
|
||||
]);
|
||||
}
|
||||
|
||||
private function getToken()
|
||||
{
|
||||
$signer = new Sha256();
|
||||
$token = (new Builder())
|
||||
->set('client_id', 'http://ownyourgram.com')
|
||||
->set('me', config('app.url'))
|
||||
->set('scope', 'create')
|
||||
->set('issued_at', time())
|
||||
->sign($signer, env('APP_KEY'))
|
||||
->getToken();
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
|
@ -46,6 +46,9 @@ class SwarmTest extends TestCase
|
|||
$this->assertDatabaseHas('places', [
|
||||
'foursquare' => 'https://foursquare.com/v/123456'
|
||||
]);
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'swarm_url' => 'https://www.swarmapp.com/checkin/abc'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue