download_manager.py 689 B

12345678910111213141516171819
  1. # download_manager.py
  2. class DownloadManager:
  3. @staticmethod
  4. def is_downloaded(name):
  5. from models.models import DownloadedFile, db
  6. # 查询数据库以检查文件是否已下载
  7. file_record = DownloadedFile.query.filter_by(name=name).first()
  8. return file_record is not None and file_record.downloaded
  9. @staticmethod
  10. def record_download(name, path):
  11. from models.models import DownloadedFile, db
  12. # 记录文件下载到数据库
  13. if not DownloadManager.is_downloaded(name):
  14. new_file = DownloadedFile(name=name, path=path, downloaded=True)
  15. db.session.add(new_file)
  16. db.session.commit()