diff options
author | Hoang Pham <hoangmaths96@gmail.com> | 2024-06-27 16:58:33 +0700 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2024-07-04 11:09:21 +0200 |
commit | 9a2f026bd675dba99c04e380cf084e6ccd5fe96d (patch) | |
tree | 353f47a3d9b3d0d5edcfd422b09673f9bd999b8d /lib/private/Repair/RepairMimeTypes.php | |
parent | 8cb0f1a3ae62790152795b66e57a6e9dd67f5996 (diff) | |
download | nextcloud-server-9a2f026bd675dba99c04e380cf084e6ccd5fe96d.tar.gz nextcloud-server-9a2f026bd675dba99c04e380cf084e6ccd5fe96d.zip |
feat: support excalidraw file
Signed-off-by: Hoang Pham <hoangmaths96@gmail.com>
Diffstat (limited to 'lib/private/Repair/RepairMimeTypes.php')
-rw-r--r-- | lib/private/Repair/RepairMimeTypes.php | 120 |
1 files changed, 97 insertions, 23 deletions
diff --git a/lib/private/Repair/RepairMimeTypes.php b/lib/private/Repair/RepairMimeTypes.php index 5aa4ee1ca95..2eece761c8d 100644 --- a/lib/private/Repair/RepairMimeTypes.php +++ b/lib/private/Repair/RepairMimeTypes.php @@ -7,6 +7,8 @@ namespace OC\Repair; use OC\Migration\NullOutput; +use OCP\DB\Exception; +use OCP\DB\IResult; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; @@ -18,7 +20,7 @@ class RepairMimeTypes implements IRepairStep { private int $changeCount = 0; /** @var int */ - protected $folderMimeTypeId; + protected int $folderMimeTypeId; public function __construct( protected IConfig $config, @@ -26,15 +28,19 @@ class RepairMimeTypes implements IRepairStep { ) { } - public function getName() { + public function getName(): string { return 'Repair mime types'; } - private function updateMimetypes($updatedMimetypes) { + /** + * @throws Exception + */ + private function updateMimetypes($updatedMimetypes): IResult|int|null { if ($this->dryRun) { $this->changeCount += count($updatedMimetypes); - return; + return null; } + $query = $this->connection->getQueryBuilder(); $query->select('id') ->from('mimetypes') @@ -82,7 +88,21 @@ class RepairMimeTypes implements IRepairStep { return $count; } - private function introduceAsciidocType() { + /** + * @throws Exception + */ + private function introduceExcalidrawType(): IResult|int|null { + $updatedMimetypes = [ + 'excalidraw' => 'application/vnd.excalidraw+json', + ]; + + return $this->updateMimetypes($updatedMimetypes); + } + + /** + * @throws Exception + */ + private function introduceAsciidocType(): IResult|int|null { $updatedMimetypes = [ 'adoc' => 'text/asciidoc', 'asciidoc' => 'text/asciidoc', @@ -91,7 +111,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceImageTypes() { + /** + * @throws Exception + */ + private function introduceImageTypes(): IResult|int|null { $updatedMimetypes = [ 'jp2' => 'image/jp2', 'webp' => 'image/webp', @@ -100,7 +123,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceWindowsProgramTypes() { + /** + * @throws Exception + */ + private function introduceWindowsProgramTypes(): IResult|int|null { $updatedMimetypes = [ 'htaccess' => 'text/plain', 'bat' => 'application/x-msdos-program', @@ -110,7 +136,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceLocationTypes() { + /** + * @throws Exception + */ + private function introduceLocationTypes(): IResult|int|null { $updatedMimetypes = [ 'gpx' => 'application/gpx+xml', 'kml' => 'application/vnd.google-earth.kml+xml', @@ -121,7 +150,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceInternetShortcutTypes() { + /** + * @throws Exception + */ + private function introduceInternetShortcutTypes(): IResult|int|null { $updatedMimetypes = [ 'url' => 'application/internet-shortcut', 'webloc' => 'application/internet-shortcut' @@ -130,7 +162,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceStreamingTypes() { + /** + * @throws Exception + */ + private function introduceStreamingTypes(): IResult|int|null { $updatedMimetypes = [ 'm3u' => 'audio/mpegurl', 'm3u8' => 'audio/mpegurl', @@ -140,7 +175,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceVisioTypes() { + /** + * @throws Exception + */ + private function introduceVisioTypes(): IResult|int|null { $updatedMimetypes = [ 'vsdm' => 'application/vnd.visio', 'vsdx' => 'application/vnd.visio', @@ -153,7 +191,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceComicbookTypes() { + /** + * @throws Exception + */ + private function introduceComicbookTypes(): IResult|int|null { $updatedMimetypes = [ 'cb7' => 'application/comicbook+7z', 'cba' => 'application/comicbook+ace', @@ -166,7 +207,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceOpenDocumentTemplates() { + /** + * @throws Exception + */ + private function introduceOpenDocumentTemplates(): IResult|int|null { $updatedMimetypes = [ 'ott' => 'application/vnd.oasis.opendocument.text-template', 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', @@ -177,7 +221,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceFlatOpenDocumentType() { + /** + * @throws Exception + */ + private function introduceFlatOpenDocumentType(): IResult|int|null { $updatedMimetypes = [ "fodt" => "application/vnd.oasis.opendocument.text-flat-xml", "fods" => "application/vnd.oasis.opendocument.spreadsheet-flat-xml", @@ -188,7 +235,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceOrgModeType() { + /** + * @throws Exception + */ + private function introduceOrgModeType(): IResult|int|null { $updatedMimetypes = [ 'org' => 'text/org' ]; @@ -196,7 +246,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceOnlyofficeFormType() { + /** + * @throws Exception + */ + private function introduceOnlyofficeFormType(): IResult|int|null { $updatedMimetypes = [ "oform" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform", "docxf" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf", @@ -205,7 +258,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceEnhancedMetafileFormatType() { + /** + * @throws Exception + */ + private function introduceEnhancedMetafileFormatType(): IResult|int|null { $updatedMimetypes = [ 'emf' => 'image/emf', ]; @@ -213,7 +269,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceEmlAndMsgFormatType() { + /** + * @throws Exception + */ + private function introduceEmlAndMsgFormatType(): IResult|int|null { $updatedMimetypes = [ 'eml' => 'message/rfc822', 'msg' => 'application/vnd.ms-outlook', @@ -222,7 +281,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceAacAudioType() { + /** + * @throws Exception + */ + private function introduceAacAudioType(): IResult|int|null { $updatedMimetypes = [ 'aac' => 'audio/aac', ]; @@ -230,7 +292,10 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } - private function introduceReStructuredTextFormatType() { + /** + * @throws Exception + */ + private function introduceReStructuredTextFormatType(): IResult|int|null { $updatedMimetypes = [ 'rst' => 'text/x-rst', ]; @@ -238,6 +303,9 @@ class RepairMimeTypes implements IRepairStep { return $this->updateMimetypes($updatedMimetypes); } + /** + * @throws Exception + */ public function migrationsAvailable(): bool { $this->dryRun = true; $this->run(new NullOutput()); @@ -250,15 +318,17 @@ class RepairMimeTypes implements IRepairStep { // 29.0.0.10 is the last version with a mimetype migration before it was moved to a separate version number if (version_compare($serverVersion, '29.0.0.10', '>')) { return $this->config->getAppValue('files', 'mimetype_version', '29.0.0.10'); - } else { - return $serverVersion; } + + return $serverVersion; } /** * Fix mime types + * + * @throws Exception */ - public function run(IOutput $out) { + public function run(IOutput $out): void { $serverVersion = $this->config->getSystemValueString('version', '0.0.0'); $mimeTypeVersion = $this->getMimeTypeVersion(); @@ -329,6 +399,10 @@ class RepairMimeTypes implements IRepairStep { $out->info('Fixed ReStructured Text mime type'); } + if (version_compare($mimeTypeVersion, '30.0.0.0', '<') && $this->introduceExcalidrawType()) { + $out->info('Fixed Excalidraw mime type'); + } + if (!$this->dryRun) { $this->config->setAppValue('files', 'mimetype_version', $serverVersion); } |