admin_demote. Admin-only route handler. This docstring was expanded to make future maintenance easier. Returns: Varies.
()
| 12168 | FILE_CATEGORIES = ( |
| 12169 | ("all", "All"), ("folders", "Folders"), ("documents", "Documents"), |
| 12170 | ("images", "Images"), ("videos", "Videos"), ("audio", "Audio"), |
| 12171 | ("archives", "Archives"), ("code", "Code"), ("apps", "Applications"), |
| 12172 | ("other", "Other"), |
| 12173 | ) |
| 12174 | _FILE_DOC_EXTS = {".pdf", ".txt", ".md", ".rtf", ".doc", ".docx", ".odt", ".xls", ".xlsx", ".ods", ".ppt", ".pptx", ".odp", ".csv", ".epub"} |
| 12175 | _FILE_IMAGE_EXTS = {".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".tif", ".tiff", ".heic", ".avif", ".svg"} |
| 12176 | _FILE_VIDEO_EXTS = {".mp4", ".webm", ".mkv", ".mov", ".avi", ".m4v", ".3gp", ".mpeg", ".mpg"} |
| 12177 | _FILE_AUDIO_EXTS = {".mp3", ".wav", ".ogg", ".oga", ".m4a", ".aac", ".flac", ".opus", ".wma"} |
| 12178 | _FILE_ARCHIVE_EXTS = {".zip", ".7z", ".rar", ".tar", ".gz", ".bz2", ".xz", ".tgz", ".apk", ".jar"} |
| 12179 | _FILE_CODE_EXTS = {".py", ".js", ".ts", ".html", ".css", ".json", ".xml", ".yaml", ".yml", ".sh", ".bash", ".java", ".c", ".h", ".cpp", ".hpp", ".cs", ".go", ".rs", ".php", ".sql", ".ini", ".toml"} |
| 12180 | _FILE_APP_EXTS = {".apk", ".exe", ".msi", ".appimage", ".deb", ".rpm", ".dmg", ".ipa"} |
| 12181 | FILE_UPLOAD_CHUNK_BYTES = 16 * 1024 * 1024 |
| 12182 | FILE_STORAGE_MAX_RATIO = 0.85 |
| 12183 | FILE_META_LOCK = threading.RLock() |
| 12184 | |
| 12185 | |
| 12186 | def _file_category(path_or_name: str, is_dir: bool = False) -> str: |
| 12187 | if is_dir: |
| 12188 | return "folders" |
| 12189 | ext = pathlib.Path(path_or_name).suffix.lower() |
| 12190 | mime = guess_mime(path_or_name).lower() |
| 12191 | if ext in _FILE_APP_EXTS: |
| 12192 | return "apps" |
| 12193 | if ext in _FILE_IMAGE_EXTS or mime.startswith("image/"): |
| 12194 | return "images" |
| 12195 | if ext in _FILE_VIDEO_EXTS or mime.startswith("video/"): |
| 12196 | return "videos" |
| 12197 | if ext in _FILE_AUDIO_EXTS or mime.startswith("audio/"): |
| 12198 | return "audio" |
| 12199 | if ext in _FILE_ARCHIVE_EXTS: |
| 12200 | return "archives" |
| 12201 | if ext in _FILE_CODE_EXTS: |
| 12202 | return "code" |
| 12203 | if ext in _FILE_DOC_EXTS or mime.startswith("text/"): |
| 12204 | return "documents" |
| 12205 | return "other" |
| 12206 | |
| 12207 | |
| 12208 | def _category_label(key: str) -> str: |
| 12209 | return dict(FILE_CATEGORIES).get(key, key.title()) |
| 12210 | |
| 12211 | |
| 12212 | def _validate_entry_name(value: str) -> str: |
| 12213 | name = (value or "").strip() |
| 12214 | if not name or name in (".", "..") or len(name) > 255: |
| 12215 | raise ValueError("bad_name") |
| 12216 | if any(ch in name for ch in ("/", "\\", "\x00", "\n", "\r")): |
| 12217 | raise ValueError("bad_name") |
nothing calls this directly
no test coverage detected