mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Add /api/v1/media/{id} endpoint
This commit is contained in:
parent
39f3e3138d
commit
fcf231f430
2 changed files with 35 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue