Mercurial > libervia-backend
diff sat/memory/memory.py @ 3288:780fb8dd07ef
core (memory/sqlite): new database schema (v9):
this new schema brings the new `public_id` column, which will be used to serve files via
HTTP, splits `mime_type` in 2 (`media_type` and `media_subtype`) to make indexing/media
filtering easier, and fixes indexes for `files` table.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 29 May 2020 21:50:49 +0200 |
parents | a3639d6d9643 |
children | b56e4c6b13fc |
line wrap: on
line diff
--- a/sat/memory/memory.py Fri May 29 21:07:10 2020 +0200 +++ b/sat/memory/memory.py Fri May 29 21:50:49 2020 +0200 @@ -22,6 +22,7 @@ import shortuuid import mimetypes import time +from pathlib import Path from uuid import uuid4 from collections import namedtuple from twisted.python import failure @@ -1293,8 +1294,8 @@ def getFiles( self, client, peer_jid, file_id=None, version=None, parent=None, path=None, type_=None, file_hash=None, hash_algo=None, name=None, namespace=None, - mime_type=None, owner=None, access=None, projection=None, unique=False, - perms_to_check=(C.ACCESS_PERM_READ,)): + mime_type=None, public_id=None, owner=None, access=None, projection=None, + unique=False, perms_to_check=(C.ACCESS_PERM_READ,)): """Retrieve files with with given filters @param peer_jid(jid.JID, None): jid trying to access the file @@ -1315,6 +1316,7 @@ @param name(unicode, None): name of the file to retrieve @param namespace(unicode, None): namespace of the files to retrieve @param mime_type(unicode, None): filter on this mime type + @param public_id(unicode, None): filter on this public id @param owner(jid.JID, None): if not None, only get files from this owner @param access(dict, None): get file with given access (see [setFile]) @param projection(list[unicode], None): name of columns to retrieve @@ -1369,6 +1371,7 @@ name=name, namespace=namespace, mime_type=mime_type, + public_id=public_id, owner=owner, access=access, projection=projection, @@ -1389,11 +1392,12 @@ @defer.inlineCallbacks def setFile( - self, client, name, file_id=None, version="", parent=None, path=None, - type_=C.FILE_TYPE_FILE, file_hash=None, hash_algo=None, size=None, - namespace=None, mime_type=None, created=None, modified=None, owner=None, - access=None, extra=None, peer_jid=None, perms_to_check=(C.ACCESS_PERM_WRITE,) - ): + self, client, name, file_id=None, version="", parent=None, path=None, + type_=C.FILE_TYPE_FILE, file_hash=None, hash_algo=None, size=None, + namespace=None, mime_type=None, public_id=None, created=None, modified=None, + owner=None, access=None, extra=None, peer_jid=None, + perms_to_check=(C.ACCESS_PERM_WRITE,) + ): """Set a file metadata @param name(unicode): basename of the file @@ -1411,6 +1415,7 @@ files For instance, namespace could be used to group files in a specific photo album @param mime_type(unicode): MIME type of the file, or None if not known/guessed + @param public_id(unicode): id used to share publicly the file via HTTP @param created(int): UNIX time of creation @param modified(int,None): UNIX time of last modification, or None to use created date @@ -1448,7 +1453,11 @@ ): raise ValueError("file_hash and hash_algo must be set at the same time") if mime_type is None: - mime_type, file_encoding = mimetypes.guess_type(name) + mime_type, __ = mimetypes.guess_type(name) + else: + mime_type = mime_type.lower() + if public_id is not None: + assert len(public_id)>0 if created is None: created = time.time() if namespace is not None: @@ -1477,6 +1486,7 @@ parent=parent, type_=C.FILE_TYPE_DIRECTORY, namespace=namespace, + public_id=public_id, created=time.time(), owner=owner, access=access, @@ -1498,6 +1508,7 @@ size=size, namespace=namespace, mime_type=mime_type, + public_id=public_id, created=created, modified=modified, owner=owner, @@ -1518,7 +1529,14 @@ return self.storage.fileUpdate(file_id, column, update_cb) @defer.inlineCallbacks - def _deleteFile(self, client, peer_jid, recursive, files_path, file_data): + def _deleteFile( + self, + client, + peer_jid: jid.JID, + recursive: bool, + files_path: Path, + file_data: dict + ): """Internal method to delete files/directories recursively @param peer_jid(jid.JID): entity requesting the deletion (must be owner of files