Also fixed issue with file editing on JS side
{
protected $fillable = ['name', 'order'];
{
protected $fillable = ['name', 'order'];
+ /**
+ * Get the downloadable file name for this upload.
+ * @return mixed|string
+ */
+ public function getFileName()
+ {
+ if (str_contains($this->name, '.')) return $this->name;
+ return $this->name . '.' . $this->extension;
+ }
+
/**
* Get the page this file was uploaded to.
* @return Page
/**
* Get the page this file was uploaded to.
* @return Page
$fileContents = $this->fileService->getFile($file);
return response($fileContents, 200, [
'Content-Type' => 'application/octet-stream',
$fileContents = $this->fileService->getFile($file);
return response($fileContents, 200, [
'Content-Type' => 'application/octet-stream',
- 'Content-Disposition' => 'attachment; filename="'. $file->name .'"'
+ 'Content-Disposition' => 'attachment; filename="'. $file->getFileName() .'"'
use BookStack\Chapter;
use BookStack\Entity;
use BookStack\Exceptions\NotFoundException;
use BookStack\Chapter;
use BookStack\Entity;
use BookStack\Exceptions\NotFoundException;
+use BookStack\Services\FileService;
use Carbon\Carbon;
use DOMDocument;
use DOMXPath;
use Carbon\Carbon;
use DOMDocument;
use DOMXPath;
$page->revisions()->delete();
$page->permissions()->delete();
$this->permissionService->deleteJointPermissionsForEntity($page);
$page->revisions()->delete();
$page->permissions()->delete();
$this->permissionService->deleteJointPermissionsForEntity($page);
+
+ // Delete AttachedFiles
+ $fileService = app(FileService::class);
+ foreach ($page->files as $file) {
+ $fileService->deleteFile($file);
+ }
+
$file = File::forceCreate([
'name' => $fileName,
'path' => $filePath,
$file = File::forceCreate([
'name' => $fileName,
'path' => $filePath,
+ 'extension' => $uploadedFile->getClientOriginalExtension(),
'uploaded_to' => $page_id,
'created_by' => user()->id,
'updated_by' => user()->id,
'uploaded_to' => $page_id,
'created_by' => user()->id,
'updated_by' => user()->id,
$file->name = $fileName;
$file->path = $filePath;
$file->external = false;
$file->name = $fileName;
$file->path = $filePath;
$file->external = false;
+ $file->extension = $uploadedFile->getClientOriginalExtension();
$file->save();
return $file;
}
$file->save();
return $file;
}
'name' => $name,
'path' => $link,
'external' => true,
'name' => $name,
'path' => $link,
'external' => true,
'uploaded_to' => $page_id,
'created_by' => user()->id,
'updated_by' => user()->id,
'uploaded_to' => $page_id,
'created_by' => user()->id,
'updated_by' => user()->id,
$table->increments('id');
$table->string('name');
$table->string('path');
$table->increments('id');
$table->string('name');
$table->string('path');
+ $table->string('extension', 20);
$table->integer('uploaded_to');
$table->boolean('external');
$table->integer('uploaded_to');
$table->boolean('external');
{
Schema::dropIfExists('files');
{
Schema::dropIfExists('files');
- // Get roles with permissions we need to change
- $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
-
// Create & attach new entity permissions
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
$entity = 'File';
foreach ($ops as $op) {
$permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
// Create & attach new entity permissions
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
$entity = 'File';
foreach ($ops as $op) {
$permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
- $permission = DB::table('role_permissions')->where('name', '=', $permName)->get();
- DB::table('permission_role')->where('permission_id', '=', $permission->id)->delete();
+ DB::table('role_permissions')->where('name', '=', $permName)->delete();
if ($scope.editFile && !file.external) {
$scope.editFile.link = '';
}
if ($scope.editFile && !file.external) {
$scope.editFile.link = '';
}
+ $scope.editFile = false;
events.emit('success', 'Attachment details updated');
});
};
events.emit('success', 'Attachment details updated');
});
};
*/
function filesIndexOf(file) {
for (let i = 0; i < $scope.files.length; i++) {
*/
function filesIndexOf(file) {
for (let i = 0; i < $scope.files.length; i++) {
- if ($scope.files[i].id == file.id) return file.id;
+ if ($scope.files[i].id == file.id) return i;