rework recreateFile function
This commit is contained in:
@@ -7,6 +7,7 @@ import pickle
|
||||
from src.logic.log import MyLogger
|
||||
from icecream import ic
|
||||
from typing import List, Tuple, Dict, Any, Optional, Union
|
||||
from pathlib import Path
|
||||
from omegaconf import OmegaConf
|
||||
from src.backend.db import CREATE_TABLE_APPARAT, CREATE_TABLE_MESSAGES, CREATE_TABLE_MEDIA, CREATE_TABLE_APPKONTOS, CREATE_TABLE_FILES, CREATE_TABLE_PROF, CREATE_TABLE_USER, CREATE_TABLE_SUBJECTS
|
||||
from src.logic.constants import SEMAP_MEDIA_ACCOUNTS
|
||||
@@ -21,6 +22,7 @@ class Database:
|
||||
def __init__(self, db_path: str = None):
|
||||
if db_path is None:
|
||||
self.db_path = config.database.path + config.database.name
|
||||
self.db_path = self.db_path.replace("~", str(Path.home()))
|
||||
else:
|
||||
self.db_path = db_path
|
||||
if self.get_db_contents() is None:
|
||||
@@ -197,12 +199,18 @@ class Database:
|
||||
blob = create_blob(path)
|
||||
query = "INSERT OR IGNORE INTO files (filename, fileblob, app_id, filetyp,prof_id) VALUES (?, ?, ?, ?,?)"
|
||||
self.query_db(query, (filename, blob, app_id, filetyp,prof_id))
|
||||
def recreateFile(self, filename, add_id):
|
||||
blob = self.getBlob(filename, add_id)
|
||||
if not os.path.exists(config.database.tempdir):
|
||||
os.mkdir(config.database.tempdir)
|
||||
tempfile.NamedTemporaryFile(filename=filename,delete=False,dir=config.database.tempdir,mode="wb").write(blob)
|
||||
|
||||
def recreateFile(self, filename, app_id,filetype):
|
||||
blob = self.getBlob(filename, app_id)
|
||||
tempdir = config.database.tempdir
|
||||
tempdir = tempdir.replace("~", str(Path.home()))
|
||||
tempdir_path = Path(tempdir)
|
||||
if not os.path.exists(tempdir_path):
|
||||
os.mkdir(tempdir_path)
|
||||
file = tempfile.NamedTemporaryFile(
|
||||
delete=False, dir=tempdir_path, mode="wb", suffix=f".{filetype}"
|
||||
)
|
||||
file.write(blob)
|
||||
return file.name
|
||||
def getFiles(self, app_id:int, prof_id:int)->list[tuple]:
|
||||
return self.query_db("SELECT filename, filetyp FROM files WHERE app_id=? AND prof_id=?", (app_id,prof_id))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user