1313use OCP \AppFramework \Db \Entity ;
1414use OCP \DB \Types ;
1515use OCP \Files \IMimeTypeDetector ;
16- use OCP \Files \IMimeTypeLoader ;
17- use OCP \Server ;
1816
1917/**
2018 * Preview entity mapped to the oc_previews and oc_preview_locations table.
3533 * @method void setHeight(int $height)
3634 * @method bool isCropped() Get whether the preview is cropped or not.
3735 * @method void setCropped(bool $cropped)
38- * @method void setMimetype (int $mimetype) Set the mimetype of the preview.
39- * @method int getMimetype () Get the mimetype of the preview.
40- * @method void setSourceMimetype (int $sourceMimetype) Set the mimetype of the source file.
41- * @method int getSourceMimetype () Get the mimetype of the source file.
36+ * @method void setMimetypeId (int $mimetype) Set the mimetype of the preview.
37+ * @method int getMimetypeId () Get the mimetype of the preview.
38+ * @method void setSourceMimetypeId (int $sourceMimetype) Set the mimetype of the source file.
39+ * @method int getSourceMimetypeId () Get the mimetype of the source file.
4240 * @method int getMtime() Get the modification time of the preview.
4341 * @method void setMtime(int $mtime)
4442 * @method int getSize() Get the size of the preview.
4745 * @method void setMax(bool $max)
4846 * @method string getEtag() Get the etag of the preview.
4947 * @method void setEtag(string $etag)
50- * @method int |null getVersion() Get the version for files_versions_s3
51- * @method void setVersion(? int $version )
48+ * @method string |null getVersion() Get the version for files_versions_s3
49+ * @method void setVersionId( int $versionId )
5250 * @method bool|null getIs() Get the version for files_versions_s3
5351 * @method bool isEncrypted() Get whether the preview is encrypted. At the moment every preview is unencrypted.
5452 * @method void setEncrypted(bool $encrypted)
@@ -64,15 +62,17 @@ class Preview extends Entity {
6462 protected ?string $ objectStoreName = null ;
6563 protected ?int $ width = null ;
6664 protected ?int $ height = null ;
67- protected ?int $ mimetype = null ;
68-
69- protected ?int $ sourceMimetype = null ;
65+ protected ?int $ mimetypeId = null ;
66+ protected ?int $ sourceMimetypeId = null ;
67+ protected string $ mimetype = 'application/octet-stream ' ;
68+ protected string $ sourceMimetype = 'application/octet-stream ' ;
7069 protected ?int $ mtime = null ;
7170 protected ?int $ size = null ;
7271 protected ?bool $ max = null ;
7372 protected ?bool $ cropped = null ;
7473 protected ?string $ etag = null ;
75- protected ?int $ version = null ;
74+ protected ?string $ version = null ;
75+ protected ?int $ versionId = null ;
7676 protected ?bool $ encrypted = null ;
7777
7878 public function __construct () {
@@ -82,23 +82,23 @@ public function __construct() {
8282 $ this ->addType ('locationId ' , Types::BIGINT );
8383 $ this ->addType ('width ' , Types::INTEGER );
8484 $ this ->addType ('height ' , Types::INTEGER );
85- $ this ->addType ('mimetype ' , Types::INTEGER );
86- $ this ->addType ('sourceMimetype ' , Types::INTEGER );
85+ $ this ->addType ('mimetypeId ' , Types::INTEGER );
86+ $ this ->addType ('sourceMimetypeId ' , Types::INTEGER );
8787 $ this ->addType ('mtime ' , Types::INTEGER );
8888 $ this ->addType ('size ' , Types::INTEGER );
8989 $ this ->addType ('max ' , Types::BOOLEAN );
9090 $ this ->addType ('cropped ' , Types::BOOLEAN );
9191 $ this ->addType ('encrypted ' , Types::BOOLEAN );
9292 $ this ->addType ('etag ' , Types::STRING );
93- $ this ->addType ('version ' , Types::BIGINT );
93+ $ this ->addType ('versionId ' , Types::STRING );
9494 }
9595
96- public static function fromPath (string $ path , IMimeTypeDetector $ mimeTypeDetector, IMimeTypeLoader $ mimeTypeLoader ): Preview |false {
96+ public static function fromPath (string $ path , IMimeTypeDetector $ mimeTypeDetector ): Preview |false {
9797 $ preview = new self ();
9898 $ preview ->setFileId ((int )basename (dirname ($ path )));
9999
100100 $ fileName = pathinfo ($ path , PATHINFO_FILENAME ) . '. ' . pathinfo ($ path , PATHINFO_EXTENSION );
101- $ ok = preg_match ('/(([0-9 ]+)-)?([0-9]+)-([0-9]+)(-(max))?(-(crop))?\.([a-z]{3,4})/ ' , $ fileName , $ matches );
101+ $ ok = preg_match ('/(([A-Za-z0-9\+\/ ]+)-)?([0-9]+)-([0-9]+)(-(max))?(-(crop))?\.([a-z]{3,4})/ ' , $ fileName , $ matches );
102102
103103 if ($ ok !== 1 ) {
104104 return false ;
@@ -108,24 +108,24 @@ public static function fromPath(string $path, IMimeTypeDetector $mimeTypeDetecto
108108 2 => $ version ,
109109 3 => $ width ,
110110 4 => $ height ,
111- 6 => $ crop ,
112- 8 => $ max ,
111+ 6 => $ max ,
112+ 8 => $ crop ,
113113 ] = $ matches ;
114114
115- $ preview ->setMimetype ( $ mimeTypeLoader -> getId ( $ mimeTypeDetector ->detectPath ($ fileName) ));
115+ $ preview ->setMimeType ( $ mimeTypeDetector ->detectPath ($ fileName ));
116116
117117 $ preview ->setWidth ((int )$ width );
118118 $ preview ->setHeight ((int )$ height );
119119 $ preview ->setCropped ($ crop === 'crop ' );
120120 $ preview ->setMax ($ max === 'max ' );
121121
122122 if (!empty ($ version )) {
123- $ preview ->setVersion (( int ) $ version );
123+ $ preview ->setVersion ($ version );
124124 }
125125 return $ preview ;
126126 }
127127
128- public function getName (IMimeTypeLoader $ mimeTypeLoader ): string {
128+ public function getName (): string {
129129 $ path = ($ this ->getVersion () > -1 ? $ this ->getVersion () . '- ' : '' ) . $ this ->getWidth () . '- ' . $ this ->getHeight ();
130130 if ($ this ->isCropped ()) {
131131 $ path .= '-crop ' ;
@@ -134,13 +134,13 @@ public function getName(IMimeTypeLoader $mimeTypeLoader): string {
134134 $ path .= '-max ' ;
135135 }
136136
137- $ ext = $ this ->getExtension ($ mimeTypeLoader );
137+ $ ext = $ this ->getExtension ();
138138 $ path .= '. ' . $ ext ;
139139 return $ path ;
140140 }
141141
142- public function getExtension (IMimeTypeLoader $ mimeTypeLoader ): string {
143- return match ($ this ->getMimetypeValue ( $ mimeTypeLoader )) {
142+ public function getExtension (): string {
143+ return match ($ this ->getMimeType ( )) {
144144 'image/png ' => 'png ' ,
145145 'image/gif ' => 'gif ' ,
146146 'image/jpeg ' => 'jpg ' ,
@@ -149,15 +149,31 @@ public function getExtension(IMimeTypeLoader $mimeTypeLoader): string {
149149 };
150150 }
151151
152- public function getMimetypeValue (IMimeTypeLoader $ mimeTypeLoader ): string {
153- return $ mimeTypeLoader ->getMimetypeById ($ this ->mimetype ) ?? 'image/jpeg ' ;
154- }
155-
156152 public function setBucketName (string $ bucketName ): void {
157153 $ this ->bucketName = $ bucketName ;
158154 }
159155
160156 public function setObjectStoreName (string $ objectStoreName ): void {
161157 $ this ->objectStoreName = $ objectStoreName ;
162158 }
159+
160+ public function setVersion (?string $ version ): void {
161+ $ this ->version = $ version ;
162+ }
163+
164+ public function getMimeType (): string {
165+ return $ this ->mimetype ;
166+ }
167+
168+ public function setMimeType (string $ mimeType ): void {
169+ $ this ->mimetype = $ mimeType ;
170+ }
171+
172+ public function getSourceMimeType (): string {
173+ return $ this ->sourceMimetype ;
174+ }
175+
176+ public function setSourceMimeType (string $ mimeType ): void {
177+ $ this ->sourceMimetype = $ mimeType ;
178+ }
163179}
0 commit comments