Compare commits
5 Commits
v0.5
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
971bdd51d2 | ||
|
|
ea843597aa | ||
|
|
b35c92b96f | ||
|
|
e420a31127 | ||
|
|
9c07870cb7 |
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
// Use 'postCreateCommand' to run commands after the container is created.
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
// "postCreateCommand": "pip3 install --user -r requirements.txt",
|
// "postCreateCommand": "pip3 install --user -r requirements.txt",
|
||||||
"postCreateCommand": ". ./env/bin/activate; python -m pip install -r requirements.txt"
|
"postCreateCommand": "python -m venv env && . ./env/bin/activate && python -m pip install -r requirements.txt"
|
||||||
|
|
||||||
// Configure tool-specific properties.
|
// Configure tool-specific properties.
|
||||||
// "customizations": {},
|
// "customizations": {},
|
||||||
|
|||||||
7
.dockerignore
Normal file
7
.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.devcontainer/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
test_db.sqlite
|
||||||
|
env/
|
||||||
|
**/__pycache__/
|
||||||
|
slopserver/alembic/
|
||||||
@@ -43,7 +43,7 @@ shellingham==1.5.4
|
|||||||
sniffio==1.3.1
|
sniffio==1.3.1
|
||||||
SQLAlchemy==2.0.44
|
SQLAlchemy==2.0.44
|
||||||
sqlmodel==0.0.27
|
sqlmodel==0.0.27
|
||||||
starlette==0.48.0
|
starlette==0.49.1
|
||||||
typer==0.19.2
|
typer==0.19.2
|
||||||
typing-inspection==0.4.2
|
typing-inspection==0.4.2
|
||||||
typing_extensions==4.15.0
|
typing_extensions==4.15.0
|
||||||
|
|||||||
@@ -34,27 +34,40 @@ def insert_slop(urls: list[ParseResult], engine: Engine, user: User | None = Non
|
|||||||
if not domain in existing_dict:
|
if not domain in existing_dict:
|
||||||
# create a new domain object and paths
|
# create a new domain object and paths
|
||||||
new_domain = Domain(domain_name=domain, paths=list())
|
new_domain = Domain(domain_name=domain, paths=list())
|
||||||
new_domain.paths = [Path(path=path) for path in paths]
|
new_paths = list()
|
||||||
|
for path in paths:
|
||||||
|
new_path = Path(path=path)
|
||||||
|
if user:
|
||||||
|
reports = list()
|
||||||
|
reports.append(Report(path=new_path, user=user, timestamp=datetime.now()))
|
||||||
|
new_path.reports = reports
|
||||||
|
new_paths.append(new_path)
|
||||||
|
new_domain.paths = new_paths
|
||||||
session.add(new_domain)
|
session.add(new_domain)
|
||||||
if user:
|
|
||||||
for path in new_domain.paths:
|
|
||||||
new_report = Report(path_id=path.id, user_id=user.id)
|
|
||||||
session.add(new_report)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
existing_domain = existing_dict[domain]
|
existing_domain = existing_dict[domain]
|
||||||
existing_paths = set((path.path for path in existing_domain.paths))
|
existing_paths = dict({path.path: path for path in existing_domain.paths})
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if not path in existing_paths:
|
if not path in existing_paths:
|
||||||
new_path = Path(path=path)
|
new_path = Path(path=path)
|
||||||
|
if user:
|
||||||
|
report_list = list()
|
||||||
|
report_list.append(Report(path=new_path, user=user, timestamp=datetime.now()))
|
||||||
|
new_path.reports = report_list
|
||||||
existing_domain.paths.append(new_path)
|
existing_domain.paths.append(new_path)
|
||||||
session.add(new_path)
|
session.add(new_path)
|
||||||
session.flush([new_path])
|
|
||||||
session.refresh(new_path)
|
else:
|
||||||
|
# domain and path exist, append to the path's reports
|
||||||
if user:
|
if user:
|
||||||
new_report = Report(
|
existing_path = existing_paths.get(path)
|
||||||
path_id=new_path.id, user_id=user.id, timestamp=datetime.now())
|
report_dict = {(report.user.id, report.path.id): report for report in existing_path.reports}
|
||||||
session.add(new_report)
|
existing_report = report_dict.get((user.id, existing_path.id))
|
||||||
|
if existing_report:
|
||||||
|
existing_report.timestamp = datetime.now()
|
||||||
|
else:
|
||||||
|
existing_path.reports.append(Report(path=existing_path, user=user, timestamp=datetime.now()))
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class Path(SQLModel, table=True):
|
|||||||
|
|
||||||
domain_id: int | None = Field(foreign_key="domain.id")
|
domain_id: int | None = Field(foreign_key="domain.id")
|
||||||
domain: Domain = Relationship(back_populates="paths")
|
domain: Domain = Relationship(back_populates="paths")
|
||||||
|
reports: list["Report"] = Relationship(back_populates="path")
|
||||||
|
|
||||||
class User(SQLModel, table=True):
|
class User(SQLModel, table=True):
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
@@ -45,11 +46,16 @@ class User(SQLModel, table=True):
|
|||||||
|
|
||||||
email_verified: bool = Field(default=False)
|
email_verified: bool = Field(default=False)
|
||||||
|
|
||||||
|
reports: list["Report"] = Relationship(back_populates="user")
|
||||||
|
|
||||||
class Report(SQLModel, table=True):
|
class Report(SQLModel, table=True):
|
||||||
path_id: int | None = Field(default=None, primary_key=True, foreign_key="path.id")
|
path_id: int | None = Field(default=None, primary_key=True, foreign_key="path.id")
|
||||||
user_id: int | None = Field(default=None, primary_key=True, foreign_key="user.id")
|
user_id: int | None = Field(default=None, primary_key=True, foreign_key="user.id")
|
||||||
timestamp: datetime | None = Field(default=datetime.now())
|
timestamp: datetime | None = Field(default=datetime.now())
|
||||||
|
|
||||||
|
path: Path = Relationship(back_populates="reports")
|
||||||
|
user: User = Relationship(back_populates="reports")
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
# API Models
|
# API Models
|
||||||
################################################
|
################################################
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ app = FastAPI()
|
|||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||||
|
|
||||||
class ServerSettings(BaseSettings):
|
class ServerSettings(BaseSettings):
|
||||||
db_url: str = "postgresql+psycopg2://slop-farmer@192.168.1.163/slop-farmer"
|
db_url: str = "sqlite+pysqlite:///test_db.sqlite"
|
||||||
token_secret: str = "5bcc778a96b090c3ac1d587bb694a060eaf7bdb5832365f91d5078faf1fff210"
|
token_secret: str = "5bcc778a96b090c3ac1d587bb694a060eaf7bdb5832365f91d5078faf1fff210"
|
||||||
# altcha_secret: str
|
# altcha_secret: str
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user