pixelfed/app/Http/Controllers/MicroController.php

67 lines
1.9 KiB
PHP
Raw Normal View History

2019-01-31 19:53:01 +00:00
<?php
namespace App\Http\Controllers;
use App\Status;
use Auth;
use DB;
2019-01-31 19:53:01 +00:00
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
class MicroController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
2019-01-31 19:53:01 +00:00
public function composeText(Request $request)
{
$this->validate($request, [
'type' => [
'required',
'string',
Rule::in(['text']),
],
'title' => 'nullable|string|max:140',
'content' => 'required|string|max:500',
'visibility' => [
'required',
'string',
Rule::in([
'public',
'unlisted',
'private',
'draft',
]),
],
]);
$profile = Auth::user()->profile;
$title = $request->input('title');
$content = $request->input('content');
$visibility = $request->input('visibility');
2019-01-31 19:53:01 +00:00
$status = DB::transaction(function () use ($profile, $content, $visibility, $title) {
$status = new Status;
$status->type = 'text';
$status->profile_id = $profile->id;
$status->caption = strip_tags($content);
$status->is_nsfw = false;
2019-01-31 19:53:01 +00:00
// TODO: remove deprecated visibility in favor of scope
$status->visibility = $visibility;
$status->scope = $visibility;
$status->entities = json_encode(['title' => $title]);
$status->save();
2019-01-31 19:53:01 +00:00
return $status;
});
$fractal = new \League\Fractal\Manager;
$fractal->setSerializer(new \League\Fractal\Serializer\ArraySerializer);
$s = new \League\Fractal\Resource\Item($status, new \App\Transformer\Api\StatusTransformer);
return $fractal->createData($s)->toArray();
}
2019-01-31 19:53:01 +00:00
}