public function package($notify = true)
{
- App::setLocale($this->user->preferredLocale());
+ //if (null !== $this->user) {
+ App::setLocale($this->user->preferredLocale());
+ //}
$res = [];
// try {
$url = $this->_compileandpackage();
}
}
} else if ($this->action === 'install') {
- echo 'Install on ' . json_encode($this->entry->install_online) . "\n";
+ //echo 'Install on ' . json_encode($this->entry->install_online) . "\n";
$s = $this->entry->install_online;
$dest = Driver::cleanInstallDir($s['path']);
/** @var FluidbookExternalInstallServer $server */
if (!FluidbookPublication::hasPermission($id, 'read')) {
abort(401);
}
- $download = new Download(FluidbookPublication::find($id), $version, $action, auth()->user());
- $url = $download->package(false);
- if (count($url)) {
- return $url[0];
- }
- return false;
+ $fluidbook = FluidbookPublication::find($id);
+ $download = new Download($fluidbook, $version, $action, auth()->user());
+ $download->package(false);
+ return $this->metadata($fluidbook);
}
public function metadata($fluidbook)
abort(401);
}
- return [
+ return response()->json([
'id' => $fluidbook->id,
'reference' => $fluidbook->reference,
'title' => $fluidbook->title,
'lang' => $fluidbook->locale,
'locale' => $fluidbook->locale,
- 'date' => (new \DateTime($fluidbook->updated_at))->getTimestamp()];
+ 'date' => (new \DateTime($fluidbook->updated_at))->getTimestamp()]);
}
public function create()
if (!can('fluidbook-publication:write')) {
abort(401);
}
-
- $job = new FluidbookEasyCreation(request('base'), Files::move_uploaded_file(request()->file('file')), request('title'), request('export'), backpack_user(), request('notify', false));
- return $job->handle();
+ $job = new FluidbookEasyCreation(request('base'), Files::move_uploaded_file(request()->file('file')), request('title'), request('export'), json_decode(request('attributes', '[]')), auth()->user(), request('notify', false));
+ return $this->metadata($job->handle()['fluidbook']);
}
- public function findByReference($reference): ?array
+ public function findByReference($reference)
{
if ($fluidbook = FluidbookPublication::where('reference', $reference)->first()) {
return $this->metadata($fluidbook);
*/
protected $export;
+ /**
+ * @var array
+ */
+ protected $attributes = [];
+
/**
* @var bool
*/
protected $notify = false;
- public function __construct($base, $file, $title, $export, $user = null, $notify = false)
+ public function __construct($base, $file, $title, $export, $attributes = [], $user = null, $notify = false)
{
parent::__construct();
$this->base = $base;
$this->title = $title;
$this->export = $export;
+ $this->attributes = $attributes;
$this->user = $user ?? backpack_user();
$this->notify = $notify;
}
$fluidbook = $base->replicateSettings();
$fluidbook->setOwner($base->owner);
$fluidbook->title = $this->title;
+ foreach ($this->attributes as $k => $v) {
+ $fluidbook->setAttribute($k, $v);
+ }
$install = false;
if ($this->export['server']) {
$install = true;
$this->install_online = $o;
}
+ public function getOnlineURL()
+ {
+ $this->checkExternalServers();
+ if (!$this->install_online->server) {
+ return null;
+ }
+ $servers = \App\Models\FluidbookExternalInstallServer::getAllServers();
+ $server = $servers[$this->install_online->server];
+ if (!$this->install_online->path && !$server['allows_root']) {
+ return null;
+ }
+ return $server['base_url'] . $this->install_online->path;
+ }
public function onSaved(): bool
{