filemgr/filemgr/filemgr.py
2025-06-26 18:06:15 +08:00

184 lines
4.7 KiB
Python

from traceback import format_exc
from ahserver.serverenv import get_serverenv
from ahserver.auth_api import get_userinfo
from sqlor.dbpools import DBPools
from appPublic.uniqueID import getID
from appPublic.log import debug, error, exception
from appbase.params import get_parmas
def get_dbname():
f = get_serverenv('get_module_dbname')
dbname = f('filemgr')
return dbname
class FileMgr:
def __init__(self, biztype):
self.biztype = biztype
async def get_bizinfo_nodes(self, request):
db = DBPools()
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
async with db.sqlorContext(dbname) as sor:
ns = {
'orgid':usrinfo.userorgid,
'biztype':self.biztype
}
recs = await sor.R('folderinfo', ns)
return recs
return []
async def add_bizinfo_node(self, request, ns):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
ns['orgid'] = userinfo.userorgid,
ns['biztype'] = self.biztype
ns['id'] = getID()
ns['cur_size'] = 0
ns['max_size'] = await get_params(sor, userinfo.userid, 'folder_max_size');
await sor.C('folderinfo', ns)
return True
return False
async def delete_bizinfo_node(self, request, ns):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
ns1['orgid'] = userinfo.userorgid,
ns1['biztype'] = self.biztype
ns1['id'] = ns['id']
await sor.D('folderinfo', ns1)
return True
return False
async def update_bizinfo_node(self, request, ns):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
ns1['orgid'] = userinfo.userorgid,
ns1['biztype'] = self.biztype
ns1['id'] = ns['id']
recs = await sor.R('folderinfo', ns1)
if len(recs) > 0:
await sor.U('folderinfo', ns1)
return True
return False
async def add_folder(self, request, ns):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
ns1['orgid'] = userinfo.userorgid,
ns1['biztype'] = self.biztype
ns1['id'] = ns['id']
await sor.C('folderinfo', ns1)
return True
return False
async def get_subfolder(self, request, fid, fiid):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
sql = """select a.id as fiid, b.*
from folderinfo a, folder b
where a.id = ${fiid}$
and b.fiid = a.id
and b.parentid = ${fid}$
and a.orgid = ${orgid}$
and a.biztype = ${biztype}$
order by name"""
ns = {
'fid':fid,
'fiid':fiid,
'orgid':userinfo.userorgid,
'biztype':self.biztype
}
recs = await sor.sqlExe(sql, ns)
return recs
await sor.D('folderinfo', ns1)
return []
async def get_files(self, request, fid, fiid):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
sql = """select a.id as fiid, b.*
from folderinfo a, file b
where a.id = ${fiid}$
and b.folderid = ${fid}$
and a.orgid = ${orgid}
and b.userid = ${userid}$
and a.biztype = ${biztype}$
order by name"""
ns = {
'fid':fid,
'fiid':fiid,
'userid':userinfo.userid,
'orgid':userinfo.userorgid,
'biztype':self.biztype
}
recs = await sor.sqlExe(sql, ns)
return recs
return []
async def get_folderinfo(self, sor, userinfo, fiid):
sql = """select * from folderinfo
where id = ${fiid}$
and orgid = ${orgid}$
and biztype = ${biztype}$"""
ns = {
'id':fiid,
'orgid':userinfo.userorgid,
'biztype':self.biztype
}
recs = await sor.sqlExe(sql, ns)
if len(recs)>0:
return recs
return None
async def add_folder(self, request, ns):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
sql = """select * from folder"""
ns1['orgid'] = userinfo.userorgid,
ns1['biztype'] = self.biztype
ns1['id'] = ns['id']
await sor.C('folderinfo', ns1)
return True
return False
async def delete_file(self, request, fid, fiid):
userinfo = await get_session_userinfo(request)
dbname = get_dbname()
db = DBPools()
async with db.sqlorContext(dbname) as sor:
sql = """select a.id as fiid, b.*
from folderinfo a, file b
where a.id = ${fiid}$
and b.id = ${fid}$
and a.orgid = ${orgid}
and b.userid = ${userid}$
and a.biztype = ${biztype}$"""
ns = {
'fid':fid,
'fiid':fiid,
'userid':userinfo.userid,
'orgid':userinfo.userorgid,
'biztype':self.biztype
}
recs = await sor.sqlExe(sql, ns)
if len(recs) > 0:
await sor.D('file', {'id': fid})
return True
return False