Add /api/v1/media/{id} endpoint

This commit is contained in:
Daniel Supernault 2019-09-25 23:01:37 -06:00
parent 39f3e3138d
commit fcf231f430
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 35 additions and 1 deletions

View file

@ -900,7 +900,8 @@ class ApiV1Controller extends Controller
];
},
'filter_name' => 'nullable|string|max:24',
'filter_class' => 'nullable|alpha_dash|max:24'
'filter_class' => 'nullable|alpha_dash|max:24',
'description' => 'nullable|string|max:420'
]);
$user = $request->user();
@ -938,6 +939,7 @@ class ApiV1Controller extends Controller
$media->original_sha256 = $hash;
$media->size = $photo->getSize();
$media->mime = $photo->getMimeType();
$media->caption = $request->input('description');
$media->filter_class = $request->input('filter_class');
$media->filter_name = $request->input('filter_name');
$media->save();
@ -962,6 +964,37 @@ class ApiV1Controller extends Controller
return response()->json($res);
}
/**
* PUT /api/v1/media/{id}
*
* @param integer $id
*
* @return App\Transformer\Api\MediaTransformer
*/
public function mediaUpdate(Request $request, $id)
{
abort_if(!$request->user(), 403);
$this->validate($request, [
'description' => 'nullable|string|max:420'
]);
$user = $request->user();
$media = Media::whereUserId($user->id)
->whereNull('status_id')
->findOrFail($id);
$media->caption = $request->input('description');
$media->save();
$resource = new Fractal\Resource\Item($media, new MediaTransformer());
$res = $this->fractal->createData($resource)->toArray();
$res['preview_url'] = url('/storage/no-preview.png');
$res['url'] = url('/storage/no-preview.png');
return response()->json($res);
}
public function statusById(Request $request, $id)
{
$status = Status::whereVisibility('public')->findOrFail($id);

View file

@ -111,6 +111,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('accounts/{id}/lists', 'Api\ApiV1Controller@accountListsById')->middleware('auth:api');
Route::get('lists/{id}/accounts', 'Api\ApiV1Controller@accountListsById')->middleware('auth:api');
Route::post('media', 'Api\ApiV1Controller@mediaUpload')->middleware('auth:api');
Route::put('media/{id}', 'Api\ApiV1Controller@mediaUpdate')->middleware('auth:api');
// Route::get('likes', 'ApiController@hydrateLikes');
// Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');