Refactoring and cleanup
This commit is contained in:
parent
e90174a09d
commit
e68a05e663
|
@ -1,13 +1,13 @@
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
from . import app, config, droppy, httpredir, pwgen, serve
|
from cista import app, config, droppy, serve, server80
|
||||||
from ._version import version
|
from cista._version import version
|
||||||
|
from cista.util import pwgen
|
||||||
|
|
||||||
app, httpredir.app # Needed for Sanic multiprocessing
|
app, server80.app # Needed for Sanic multiprocessing
|
||||||
|
|
||||||
doc = f"""Cista {version} - A file storage for the web.
|
doc = f"""Cista {version} - A file storage for the web.
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,10 @@ from sanic import Forbidden, Sanic, SanicException, errorpages
|
||||||
from sanic.log import logger
|
from sanic.log import logger
|
||||||
from sanic.response import html, json, redirect
|
from sanic.response import html, json, redirect
|
||||||
|
|
||||||
from . import config, session, watching
|
from cista import config, session, watching
|
||||||
from .auth import authbp
|
from cista.auth import authbp
|
||||||
from .fileio import FileServer
|
from cista.fileio import FileServer
|
||||||
from .protocol import ControlBase, ErrorMsg, FileRange, StatusMsg
|
from cista.protocol import ControlBase, ErrorMsg, FileRange, StatusMsg
|
||||||
|
|
||||||
|
|
||||||
app = Sanic("cista")
|
app = Sanic("cista")
|
||||||
fileserver = FileServer()
|
fileserver = FileServer()
|
||||||
|
|
|
@ -8,7 +8,7 @@ import msgspec
|
||||||
from html5tagger import Document
|
from html5tagger import Document
|
||||||
from sanic import BadRequest, Blueprint, Forbidden, html, json, redirect
|
from sanic import BadRequest, Blueprint, Forbidden, html, json, redirect
|
||||||
|
|
||||||
from . import config, session
|
from cista import config, session
|
||||||
|
|
||||||
_argon = argon2.PasswordHasher()
|
_argon = argon2.PasswordHasher()
|
||||||
_droppyhash = re.compile(r'^([a-f0-9]{64})\$([a-f0-9]{8})$')
|
_droppyhash = re.compile(r'^([a-f0-9]{64})\$([a-f0-9]{8})$')
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from pathlib import Path, PurePosixPath
|
from pathlib import PurePosixPath
|
||||||
|
|
||||||
from pathvalidate import sanitize_filepath
|
from pathvalidate import sanitize_filepath
|
||||||
|
|
||||||
from . import config, protocol
|
from cista import config
|
||||||
from .asynclink import AsyncLink
|
from cista.util.asynclink import AsyncLink
|
||||||
from .lrucache import LRUCache
|
from cista.util.lrucache import LRUCache
|
||||||
|
|
||||||
|
|
||||||
def fuid(stat) -> str:
|
def fuid(stat) -> str:
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
import msgspec
|
||||||
from sanic import BadRequest
|
from sanic import BadRequest
|
||||||
|
|
||||||
from cista import config
|
from cista import config
|
||||||
from cista.fileio import sanitize_filename
|
from cista.fileio import sanitize_filename
|
||||||
|
|
||||||
import msgspec
|
|
||||||
|
|
||||||
## Control commands
|
## Control commands
|
||||||
|
|
||||||
class ControlBase(msgspec.Struct, tag_field="op", tag=str.lower):
|
class ControlBase(msgspec.Struct, tag_field="op", tag=str.lower):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
|
|
||||||
from . import config
|
from cista import config
|
||||||
|
|
||||||
|
|
||||||
def run(dev=False):
|
def run(dev=False):
|
||||||
|
@ -15,8 +15,8 @@ def run(dev=False):
|
||||||
os.environ["SANIC_IGNORE_PRODUCTION_WARNING"] = "1"
|
os.environ["SANIC_IGNORE_PRODUCTION_WARNING"] = "1"
|
||||||
if opts.get("ssl"):
|
if opts.get("ssl"):
|
||||||
# Run plain HTTP redirect/acme server on port 80
|
# Run plain HTTP redirect/acme server on port 80
|
||||||
from . import httpredir
|
from . import server80
|
||||||
httpredir.app.prepare(port=80, motd=False)
|
server80.app.prepare(port=80, motd=False)
|
||||||
domain = opts["host"]
|
domain = opts["host"]
|
||||||
opts["ssl"] = str(config.conffile.parent / domain)
|
opts["ssl"] = str(config.conffile.parent / domain)
|
||||||
app.prepare(**opts, motd=False, dev=dev, auto_reload=dev, access_log=True)
|
app.prepare(**opts, motd=False, dev=dev, auto_reload=dev, access_log=True)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from sanic import Sanic, exceptions, response
|
from sanic import Sanic, exceptions, response
|
||||||
|
|
||||||
app = Sanic("http_redirect")
|
app = Sanic("server80")
|
||||||
|
|
||||||
# Send all HTTP users to HTTPS
|
# Send all HTTP users to HTTPS
|
||||||
@app.exception(exceptions.NotFound, exceptions.MethodNotSupported)
|
@app.exception(exceptions.NotFound, exceptions.MethodNotSupported)
|
|
@ -2,7 +2,7 @@ from time import time
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
|
|
||||||
from .config import derived_secret
|
from cista.config import derived_secret
|
||||||
|
|
||||||
session_secret = lambda: derived_secret("session")
|
session_secret = lambda: derived_secret("session")
|
||||||
max_age = 60 # Seconds since last login
|
max_age = 60 # Seconds since last login
|
||||||
|
|
|
@ -2,13 +2,12 @@ import asyncio
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from pathlib import Path, PurePosixPath
|
from pathlib import Path, PurePosixPath
|
||||||
from socket import timeout
|
|
||||||
|
|
||||||
import inotify.adapters
|
import inotify.adapters
|
||||||
import msgspec
|
import msgspec
|
||||||
|
|
||||||
from . import config
|
from cista import config
|
||||||
from .protocol import DirEntry, FileEntry, UpdateEntry
|
from cista.protocol import DirEntry, FileEntry, UpdateEntry
|
||||||
|
|
||||||
pubsub = {}
|
pubsub = {}
|
||||||
tree = {"": None}
|
tree = {"": None}
|
||||||
|
|
|
@ -3,7 +3,7 @@ from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from cista.lrucache import LRUCache # Replace with actual import
|
from cista.util.lrucache import LRUCache # Replace with actual import
|
||||||
|
|
||||||
|
|
||||||
def mock_open(key):
|
def mock_open(key):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user