use BookStack\Exceptions\FileUploadException;
use Exception;
+use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class AttachmentService extends UploadService
*/
protected function getStorage()
{
- $storageType = config('filesystems.default');
+ $storageType = config('filesystems.attachments');
// Override default location if set to local public to ensure not visible.
if ($storageType === 'local') {
}
/**
- * Updates the file ordering for a listing of attached files.
- * @param array $attachmentList
- * @param $pageId
+ * Updates the ordering for a listing of attached files.
*/
- public function updateFileOrderWithinPage($attachmentList, $pageId)
+ public function updateFileOrderWithinPage(array $attachmentOrder, string $pageId)
{
- foreach ($attachmentList as $index => $attachment) {
- Attachment::where('uploaded_to', '=', $pageId)->where('id', '=', $attachment['id'])->update(['order' => $index]);
+ foreach ($attachmentOrder as $index => $attachmentId) {
+ Attachment::query()->where('uploaded_to', '=', $pageId)
+ ->where('id', '=', $attachmentId)
+ ->update(['order' => $index]);
}
}
$storage = $this->getStorage();
$basePath = 'uploads/files/' . Date('Y-m-M') . '/';
- $uploadFileName = str_random(16) . '.' . $uploadedFile->getClientOriginalExtension();
+ $uploadFileName = Str::random(16) . '.' . $uploadedFile->getClientOriginalExtension();
while ($storage->exists($basePath . $uploadFileName)) {
- $uploadFileName = str_random(3) . $uploadFileName;
+ $uploadFileName = Str::random(3) . $uploadFileName;
}
$attachmentPath = $basePath . $uploadFileName;