[ 'fileType' => $document->office_extension, 'key' => $document->office_key, 'title' => $document->name.'.'.$document->office_extension, 'url' => $this->downloadUrl($document), ], 'documentType' => $this->documentType($document->office_extension), 'editorConfig' => [ 'mode' => $editable ? 'edit' : 'view', 'callbackUrl' => $this->callbackUrl($document), 'user' => [ 'id' => (string) $user->id, 'name' => $user->name, ], 'lang' => 'fr', ], ]; $secret = config('onlyoffice.jwt_secret'); if (filled($secret)) { $config['token'] = JWT::encode($config, $secret, 'HS256'); } return $config; } protected function downloadUrl(Document $document): string { $signed = URL::temporarySignedRoute( 'onlyoffice.download', now()->addMinutes(5), ['document' => $document->id], absolute: false ); return $this->baseUrl().$signed; } protected function callbackUrl(Document $document): string { return $this->baseUrl().route('onlyoffice.callback', $document, absolute: false); } protected function baseUrl(): string { return rtrim(config('onlyoffice.callback_base_url'), '/'); } protected function documentType(?string $extension): string { return match ($extension) { 'xlsx' => 'cell', 'pptx' => 'slide', default => 'word', }; } }