File size: 2,299 Bytes
b37ebd1
 
 
a1983b7
b37ebd1
 
 
 
 
 
120bd9a
 
 
 
 
b37ebd1
 
 
 
120bd9a
b37ebd1
 
120bd9a
a1983b7
 
120bd9a
b37ebd1
3998cca
 
 
 
 
 
4e64e70
120bd9a
 
 
 
b37ebd1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from datetime import datetime
from typing import Optional

from sqlalchemy import BigInteger, Boolean, DateTime, ForeignKey, Integer, String, func
from sqlalchemy.orm import Mapped, mapped_column

from app.db.base import Base


class Material(Base):
    """A file served to students by Telegram file_id.

    library_chat_id/library_message_id point to a backup copy in the private
    library channel (so files can be re-indexed if the bot token ever changes).
    """

    __tablename__ = "materials"

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    course_id: Mapped[Optional[int]] = mapped_column(ForeignKey("courses.id"), index=True)
    kind: Mapped[str] = mapped_column(String(16), default="slide")  # slide|exam|note|book
    title: Mapped[str] = mapped_column(String(256))
    file_id: Mapped[Optional[str]] = mapped_column(String(512))
    orig_file_id: Mapped[Optional[str]] = mapped_column(String(512))  # the file as uploaded (before the stamp)
    watermarked: Mapped[bool] = mapped_column(Boolean, default=False, server_default="false")
    file_type: Mapped[str] = mapped_column(String(16), default="document", server_default="document")
    file_unique_id: Mapped[Optional[str]] = mapped_column(String(128), unique=True)
    content_hash: Mapped[Optional[str]] = mapped_column(String(64), index=True)  # sha256 of the bytes
    text_sig: Mapped[Optional[int]] = mapped_column(BigInteger)  # SimHash of the text (near-duplicates)
    pages: Mapped[Optional[int]] = mapped_column(Integer)
    size: Mapped[Optional[int]] = mapped_column(Integer)
    source_name: Mapped[Optional[str]] = mapped_column(String(256))  # original file name
    status: Mapped[str] = mapped_column(String(8), default="ok", server_default="ok")  # ok | review
    credit: Mapped[Optional[str]] = mapped_column(String(40))  # contributor name, if they chose to be credited
    downloads: Mapped[int] = mapped_column(Integer, default=0, server_default="0")
    uploader_id: Mapped[Optional[int]] = mapped_column(BigInteger)
    library_chat_id: Mapped[Optional[int]] = mapped_column(BigInteger)
    library_message_id: Mapped[Optional[int]] = mapped_column(BigInteger)
    created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())