mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-16 16:36:08 +08:00
Add route for updating file
This commit is contained in:
parent
35d6d3777c
commit
b01afb4f3d
4 changed files with 44 additions and 6 deletions
|
@ -46,6 +46,7 @@ return [
|
|||
['name' => 'file#uploadFile', 'url' => '/api/v2/file', 'verb' => 'POST'],
|
||||
['name' => 'file#getFile', 'url' => '/api/v2/file/{file_id}', 'verb' => 'GET'],
|
||||
['name' => 'file#deleteFile', 'url' => '/api/v2/file/{file_id}', 'verb' => 'DELETE'],
|
||||
['name' => 'file#updateFile', 'url' => '/api/v2/file/{file_id}', 'verb' => 'PATCH'],
|
||||
|
||||
//Sharing stuff
|
||||
['name' => 'share#search', 'url' => '/api/v2/sharing/search', 'verb' => 'POST'],
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace OCA\Passman\Controller;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\ApiController;
|
||||
|
@ -54,4 +55,23 @@ class FileController extends ApiController {
|
|||
public function deleteFile($file_id) {
|
||||
return $this->fileService->deleteFile($file_id, $this->userId);
|
||||
}
|
||||
|
||||
public function updateFile($file_id, $data, $filename, $mimetype, $size){
|
||||
try{
|
||||
$file = $this->fileService->getFile($file_id, $this->userId);
|
||||
} catch (DoesNotExistException $doesNotExistException){
|
||||
|
||||
}
|
||||
if($file){
|
||||
if($data) {
|
||||
$file->setFileData($data);
|
||||
}
|
||||
if($filename) {
|
||||
$file->setFilename($filename);
|
||||
}
|
||||
if($filename || $data){
|
||||
$this->fileService->updateFile($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ use OCP\AppFramework\Db\Mapper;
|
|||
|
||||
class FileMapper extends Mapper {
|
||||
private $utils;
|
||||
|
||||
public function __construct(IDBConnection $db, Utils $utils) {
|
||||
parent::__construct($db, 'passman_files');
|
||||
$this->utils = $utils;
|
||||
|
@ -23,16 +24,24 @@ class FileMapper extends Mapper {
|
|||
|
||||
|
||||
/**
|
||||
* @param $file_id
|
||||
* @param null $user_id
|
||||
* @return File
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||
*/
|
||||
public function getFile($file_id, $user_id) {
|
||||
public function getFile($file_id, $user_id = null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*passman_files` ' .
|
||||
'WHERE `id` = ? and `user_id` = ? ';
|
||||
return $this->findEntities($sql, [$file_id, $user_id]);
|
||||
'WHERE `id` = ?';
|
||||
$params = [$file_id];
|
||||
if ($user_id !== null) {
|
||||
$sql .= ' and `user_id` = ? ';
|
||||
array_push($params, $user_id);
|
||||
}
|
||||
return $this->findEntities($sql, $params);
|
||||
}
|
||||
|
||||
public function create($file_raw, $userId){
|
||||
public function create($file_raw, $userId) {
|
||||
$file = new File();
|
||||
$file->setGuid($this->utils->GUID());
|
||||
$file->setUserId($userId);
|
||||
|
@ -52,4 +61,8 @@ class FileMapper extends Mapper {
|
|||
$file->setUserId($userId);
|
||||
$this->delete($file);
|
||||
}
|
||||
|
||||
public function updateFile(File $file) {
|
||||
return $this->update($file);
|
||||
}
|
||||
}
|
|
@ -25,8 +25,8 @@ class FileService {
|
|||
$this->fileMapper = $fileMapper;
|
||||
}
|
||||
|
||||
public function getFile($userId, $fileId) {
|
||||
return $this->fileMapper->getFile($userId, $fileId);
|
||||
public function getFile($fileId, $userId = null) {
|
||||
return $this->fileMapper->getFile($fileId, $userId);
|
||||
}
|
||||
|
||||
public function createFile($file, $userId) {
|
||||
|
@ -37,4 +37,8 @@ class FileService {
|
|||
return $this->fileMapper->deleteFile($file_id, $userId);
|
||||
}
|
||||
|
||||
public function updateFile($file_id) {
|
||||
return $this->fileMapper->updateFile($file_id);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue