Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/DIMOC-208/fileupload-fe #119

Merged
merged 16 commits into from
Aug 7, 2024
Merged

Conversation

remko48
Copy link
Contributor

@remko48 remko48 commented Aug 7, 2024

No description provided.

Comment on lines +126 to +151
public function uploadFile(mixed $content, ?string $filePath = '', ?bool $update = false): bool
{
// Get the admin username & password for auth & get the current username
$userInfo = $this->getUserInfo();

// API endpoint to upload the file
$url = $this->getCurrentDomain() . '/remote.php/dav/files/'
. $userInfo['currentUsername'] . '/' . ltrim(string: $filePath, characters: '/');

try {
$response = $this->client->request('PUT', $url, [
'auth' => [$userInfo['username'], $userInfo['password']],
'body' => $content
]);

if ($response->getStatusCode() === 201 || ($update === true && $response->getStatusCode() === 204)) {
return true;
}
} catch (\Exception $e) {
$str = $update === true ? 'update' : 'upload';
$this->logger->error("File $str failed: " . $e->getMessage());
throw $e;
}

return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waarom buitenom via de API als er een interne route voor bestaat?

Comment on lines +161 to +184
public function deleteFile(string $filePath): bool
{
// Get the admin username & password for auth & get the current username
$userInfo = $this->getUserInfo();

// API endpoint to upload the file
$url = $this->getCurrentDomain() . '/remote.php/dav/files/'
. $userInfo['currentUsername'] . '/' . ltrim(string: $filePath, characters: '/');

try {
$response = $this->client->request('DELETE', $url, [
'auth' => [$userInfo['username'], $userInfo['password']],
]);

if ($response->getStatusCode() === 204) {
return true;
}
} catch (\Exception $e) {
$this->logger->error('File deletion failed: ' . $e->getMessage());
throw $e;
}

return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem, waarom buitenom als er een interne route voor is?

@remko48 remko48 merged commit 024dd9e into development Aug 7, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants