12345678910111213141516171819 |
- # download_manager.py
- class DownloadManager:
- @staticmethod
- def is_downloaded(name):
- from models.models import DownloadedFile, db
- # 查询数据库以检查文件是否已下载
- file_record = DownloadedFile.query.filter_by(name=name).first()
- return file_record is not None and file_record.downloaded
- @staticmethod
- def record_download(name, path):
- from models.models import DownloadedFile, db
- # 记录文件下载到数据库
- if not DownloadManager.is_downloaded(name):
- new_file = DownloadedFile(name=name, path=path, downloaded=True)
- db.session.add(new_file)
- db.session.commit()
|