init
This commit is contained in:
commit
a426df12c0
22 changed files with 2819 additions and 0 deletions
964
.gitignore
vendored
Normal file
964
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,964 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode
|
||||
|
||||
### Data ###
|
||||
*.csv
|
||||
*.dat
|
||||
*.efx
|
||||
*.gbr
|
||||
*.key
|
||||
*.pps
|
||||
*.ppt
|
||||
*.pptx
|
||||
*.sdf
|
||||
*.tax2010
|
||||
*.vcf
|
||||
*.xml
|
||||
|
||||
### Emacs ###
|
||||
# -*- mode: gitignore; -*-
|
||||
*~
|
||||
\#*\#
|
||||
/.emacs.desktop
|
||||
/.emacs.desktop.lock
|
||||
*.elc
|
||||
auto-save-list
|
||||
tramp
|
||||
.\#*
|
||||
|
||||
# Org-mode
|
||||
.org-id-locations
|
||||
*_archive
|
||||
|
||||
# flymake-mode
|
||||
*_flymake.*
|
||||
|
||||
# eshell files
|
||||
/eshell/history
|
||||
/eshell/lastdir
|
||||
|
||||
# elpa packages
|
||||
/elpa/
|
||||
|
||||
# reftex files
|
||||
*.rel
|
||||
|
||||
# AUCTeX auto folder
|
||||
/auto/
|
||||
|
||||
# cask packages
|
||||
.cask/
|
||||
dist/
|
||||
|
||||
# Flycheck
|
||||
flycheck_*.el
|
||||
|
||||
# server auth directory
|
||||
/server/
|
||||
|
||||
# projectiles files
|
||||
.projectile
|
||||
|
||||
# directory configuration
|
||||
.dir-locals.el
|
||||
|
||||
# network security
|
||||
/network-security.data
|
||||
|
||||
|
||||
### Executable ###
|
||||
*.app
|
||||
*.bat
|
||||
*.cgi
|
||||
*.com
|
||||
*.exe
|
||||
*.gadget
|
||||
*.jar
|
||||
*.pif
|
||||
*.vb
|
||||
*.wsf
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
### Node Patch ###
|
||||
# Serverless Webpack directories
|
||||
.webpack/
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
# SvelteKit build / generate output
|
||||
.svelte-kit
|
||||
|
||||
### PyCharm ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### PyCharm Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator-enh.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
.idea/codestream.xml
|
||||
|
||||
# Azure Toolkit for IntelliJ plugin
|
||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||
.idea/**/azureSettings.xml
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
### Python Patch ###
|
||||
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
||||
poetry.toml
|
||||
|
||||
# ruff
|
||||
.ruff_cache/
|
||||
|
||||
# LSP config files
|
||||
pyrightconfig.json
|
||||
|
||||
### SublimeText ###
|
||||
# Cache files for Sublime Text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
|
||||
# Workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
|
||||
# Project files should be checked into the repository, unless a significant
|
||||
# proportion of contributors will probably not be using Sublime Text
|
||||
# *.sublime-project
|
||||
|
||||
# SFTP configuration file
|
||||
sftp-config.json
|
||||
sftp-config-alt*.json
|
||||
|
||||
# Package control specific files
|
||||
Package Control.last-run
|
||||
Package Control.ca-list
|
||||
Package Control.ca-bundle
|
||||
Package Control.system-ca-bundle
|
||||
Package Control.cache/
|
||||
Package Control.ca-certs/
|
||||
Package Control.merged-ca-bundle
|
||||
Package Control.user-ca-bundle
|
||||
oscrypto-ca-bundle.crt
|
||||
bh_unicode_properties.cache
|
||||
|
||||
# Sublime-github package stores a github token in this file
|
||||
# https://packagecontrol.io/packages/sublime-github
|
||||
GitHub.sublime-settings
|
||||
|
||||
### Vim ###
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
Sessionx.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
### VisualStudio ###
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||
*.vbp
|
||||
|
||||
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||
*.dsw
|
||||
*.dsp
|
||||
|
||||
# Visual Studio 6 technical files
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# Visual Studio History (VSHistory) files
|
||||
.vshistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
### VisualStudio Patch ###
|
||||
# Additional files built by Visual Studio
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode
|
||||
9
LICENSE.txt
Normal file
9
LICENSE.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2024-present U.N. Owen <void@some.where>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
21
README.md
Normal file
21
README.md
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# FastApi Dynamic Response
|
||||
|
||||
[](https://pypi.org/project/fastapi-dynamic-response)
|
||||
[](https://pypi.org/project/fastapi-dynamic-response)
|
||||
|
||||
-----
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Installation](#installation)
|
||||
- [License](#license)
|
||||
|
||||
## Installation
|
||||
|
||||
```console
|
||||
pip install fastapi-dynamic-response
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
`fastapi-dynamic-response` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
||||
BIN
img.png
Normal file
BIN
img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
4
justfile
Normal file
4
justfile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
venv:
|
||||
uv venv
|
||||
run:
|
||||
uv run -- uvicorn --reload --log-level debug src.fastapi_dynamic_response.main:app
|
||||
73
pyproject.toml
Normal file
73
pyproject.toml
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "fastapi-dynamic-response"
|
||||
dynamic = ["version"]
|
||||
description = 'A demo fastapi application that automatically responds to user preferences for output format.'
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.8"
|
||||
license = "MIT"
|
||||
keywords = []
|
||||
authors = [
|
||||
{ name = "U.N. Owen", email = "void@some.where" },
|
||||
]
|
||||
classifiers = [
|
||||
"Development Status :: 4 - Beta",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
]
|
||||
dependencies = [
|
||||
"fastapi>=0.115.0",
|
||||
"html2text>=2024.2.26",
|
||||
"jinja2>=3.1.4",
|
||||
"markdown>=3.7",
|
||||
"pillow>=10.4.0",
|
||||
"pydyf==0.8.0",
|
||||
"python-levenshtein>=0.25.1",
|
||||
"rich>=13.9.2",
|
||||
"selenium>=4.25.0",
|
||||
"uvicorn>=0.31.1",
|
||||
"weasyprint>=61.2",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Documentation = "https://github.com/U.N. Owen/fastapi-dynamic-response#readme"
|
||||
Issues = "https://github.com/U.N. Owen/fastapi-dynamic-response/issues"
|
||||
Source = "https://github.com/U.N. Owen/fastapi-dynamic-response"
|
||||
|
||||
[tool.hatch.version]
|
||||
path = "src/fastapi_dynamic_response/__about__.py"
|
||||
|
||||
[tool.hatch.envs.types]
|
||||
extra-dependencies = [
|
||||
"mypy>=1.0.0",
|
||||
]
|
||||
[tool.hatch.envs.types.scripts]
|
||||
check = "mypy --install-types --non-interactive {args:src/fastapi_dynamic_response tests}"
|
||||
|
||||
[tool.coverage.run]
|
||||
source_pkgs = ["fastapi_dynamic_response", "tests"]
|
||||
branch = true
|
||||
parallel = true
|
||||
omit = [
|
||||
"src/fastapi_dynamic_response/__about__.py",
|
||||
]
|
||||
|
||||
[tool.coverage.paths]
|
||||
fastapi_dynamic_response = ["src/fastapi_dynamic_response", "*/fastapi-dynamic-response/src/fastapi_dynamic_response"]
|
||||
tests = ["tests", "*/fastapi-dynamic-response/tests"]
|
||||
|
||||
[tool.coverage.report]
|
||||
exclude_lines = [
|
||||
"no cov",
|
||||
"if __name__ == .__main__.:",
|
||||
"if TYPE_CHECKING:",
|
||||
]
|
||||
4
src/fastapi_dynamic_response/__about__.py
Normal file
4
src/fastapi_dynamic_response/__about__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2024-present U.N. Owen <void@some.where>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = "0.0.1"
|
||||
3
src/fastapi_dynamic_response/__init__.py
Normal file
3
src/fastapi_dynamic_response/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2024-present U.N. Owen <void@some.where>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
38
src/fastapi_dynamic_response/base/router.py
Normal file
38
src/fastapi_dynamic_response/base/router.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi_dynamic_response.base.schema import Message
|
||||
from fastapi_dynamic_response.dependencies import get_content_type
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/example")
|
||||
async def get_example(
|
||||
request: Request,
|
||||
content_type: str = Depends(get_content_type),
|
||||
):
|
||||
request.state.template_name = "example.html"
|
||||
return {"message": "Hello, this is an example", "data": [1, 2, 3, 4]}
|
||||
|
||||
|
||||
@router.get("/another-example")
|
||||
async def another_example(
|
||||
request: Request,
|
||||
content_type: str = Depends(get_content_type),
|
||||
):
|
||||
request.state.template_name = "another_example.html"
|
||||
return {
|
||||
"title": "Another Example",
|
||||
"message": "Your cart",
|
||||
"items": ["apple", "banana", "cherry"],
|
||||
}
|
||||
|
||||
|
||||
@router.post("/message")
|
||||
async def message(
|
||||
request: Request,
|
||||
message: Message,
|
||||
content_type: str = Depends(get_content_type),
|
||||
):
|
||||
request.state.template_name = "post_message.html"
|
||||
return {"message": message.message}
|
||||
5
src/fastapi_dynamic_response/base/schema.py
Normal file
5
src/fastapi_dynamic_response/base/schema.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Message(BaseModel):
|
||||
message: str
|
||||
9
src/fastapi_dynamic_response/dependencies.py
Normal file
9
src/fastapi_dynamic_response/dependencies.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from fastapi import Query
|
||||
|
||||
|
||||
def get_content_type(
|
||||
content_type: str = Query(
|
||||
None, description="Specify the content type of the response"
|
||||
),
|
||||
):
|
||||
return content_type
|
||||
4
src/fastapi_dynamic_response/globals.py
Normal file
4
src/fastapi_dynamic_response/globals.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
is_ready = False
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
36
src/fastapi_dynamic_response/main.py
Normal file
36
src/fastapi_dynamic_response/main.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from fastapi import Depends, FastAPI, Request
|
||||
from fastapi_dynamic_response import globals
|
||||
from fastapi_dynamic_response.base.router import router as base_router
|
||||
from fastapi_dynamic_response.dependencies import get_content_type
|
||||
from fastapi_dynamic_response.middleware import (
|
||||
catch_exceptions_middleware,
|
||||
respond_based_on_content_type,
|
||||
)
|
||||
from fastapi_dynamic_response.zpages.router import router as zpages_router
|
||||
|
||||
|
||||
app = FastAPI(debug=True)
|
||||
app.include_router(zpages_router)
|
||||
app.include_router(base_router)
|
||||
app.middleware("http")(catch_exceptions_middleware)
|
||||
app.middleware("http")(respond_based_on_content_type)
|
||||
|
||||
|
||||
# Flag to indicate if the application is ready
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
# Perform startup actions, e.g., database connections
|
||||
# If all startup actions are successful, set is_ready to True
|
||||
globals.is_ready = True
|
||||
|
||||
|
||||
@app.get("/sitemap")
|
||||
async def sitemap(
|
||||
request: Request,
|
||||
content_type: str = Depends(get_content_type),
|
||||
):
|
||||
request.state.template_name = "sitemap.html"
|
||||
available_routes = [route.path for route in app.router.routes if route.path]
|
||||
return {"available_routes": available_routes}
|
||||
229
src/fastapi_dynamic_response/middleware.py
Normal file
229
src/fastapi_dynamic_response/middleware.py
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
from difflib import get_close_matches
|
||||
from fastapi import Request, Response
|
||||
from fastapi.exceptions import (
|
||||
HTTPException as StarletteHTTPException,
|
||||
RequestValidationError,
|
||||
)
|
||||
from fastapi.responses import HTMLResponse, JSONResponse, PlainTextResponse
|
||||
import html2text
|
||||
from io import BytesIO
|
||||
import json
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
from rich.panel import Panel
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
import traceback
|
||||
from weasyprint import HTML as WeasyHTML
|
||||
|
||||
from fastapi_dynamic_response.globals import templates
|
||||
|
||||
|
||||
async def catch_exceptions_middleware(request: Request, call_next):
|
||||
try:
|
||||
return await call_next(request)
|
||||
except Exception as e:
|
||||
print(traceback.format_exc())
|
||||
raise e
|
||||
|
||||
|
||||
def is_browser_request(user_agent: str) -> bool:
|
||||
browser_keywords = [
|
||||
"mozilla",
|
||||
"chrome",
|
||||
"safari",
|
||||
"firefox",
|
||||
"edge",
|
||||
"wget",
|
||||
"opera",
|
||||
]
|
||||
return any(keyword in user_agent.lower() for keyword in browser_keywords)
|
||||
|
||||
|
||||
def is_rtf_request(user_agent: str) -> bool:
|
||||
rtf_keywords = ["curl", "httpie", "httpx"]
|
||||
return any(keyword in user_agent.lower() for keyword in rtf_keywords)
|
||||
|
||||
|
||||
def get_screenshot(html_content: str) -> BytesIO:
|
||||
chrome_options = Options()
|
||||
chrome_options.add_argument("--headless")
|
||||
chrome_options.add_argument("--disable-gpu")
|
||||
chrome_options.add_argument("--no-sandbox")
|
||||
chrome_options.add_argument("--window-size=1280x1024")
|
||||
|
||||
driver = webdriver.Chrome(options=chrome_options)
|
||||
driver.get("data:text/html;charset=utf-8," + html_content)
|
||||
screenshot = driver.get_screenshot_as_png()
|
||||
driver.quit()
|
||||
buffer = BytesIO(screenshot)
|
||||
return buffer
|
||||
|
||||
|
||||
def format_json_as_plain_text(data: dict) -> str:
|
||||
"""Convert JSON to human-readable plain text format with indentation and bullet points."""
|
||||
|
||||
def _format_value(value, indent=2):
|
||||
if isinstance(value, dict):
|
||||
return format_json_as_plain_text(value)
|
||||
elif isinstance(value, list):
|
||||
return "\n".join([f"{' ' * indent}- {item}" for item in value])
|
||||
else:
|
||||
return str(value)
|
||||
|
||||
output_lines = []
|
||||
for key, value in data.items():
|
||||
if isinstance(value, (dict, list)):
|
||||
output_lines.append(f"{key}:\n{_format_value(value)}")
|
||||
else:
|
||||
output_lines.append(f"{key}: {value}")
|
||||
return "\n".join(output_lines)
|
||||
|
||||
|
||||
def format_json_as_rich_text(data: dict, template_name: str) -> str:
|
||||
"""Convert JSON to a human-readable rich text format using rich."""
|
||||
|
||||
console = Console()
|
||||
# pretty_data = Pretty(data, indent_guides=True)
|
||||
|
||||
template = templates.get_template(template_name)
|
||||
html_content = template.render(data=data)
|
||||
markdown_content = html2text.html2text(html_content)
|
||||
|
||||
with console.capture() as capture:
|
||||
console.print(
|
||||
Panel(
|
||||
Markdown(markdown_content),
|
||||
title="Response Data",
|
||||
border_style="bold cyan",
|
||||
)
|
||||
)
|
||||
|
||||
return capture.get()
|
||||
|
||||
|
||||
def handle_not_found(request: Request, data: str):
|
||||
requested_path = request.url.path
|
||||
available_routes = [route.path for route in app.router.routes if route.path]
|
||||
suggestions = get_close_matches(requested_path, available_routes, n=3, cutoff=0.5)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"404.html",
|
||||
{
|
||||
"request": request,
|
||||
"data": json.loads(data),
|
||||
"available_routes": available_routes,
|
||||
"requested_path": requested_path,
|
||||
"suggestions": suggestions,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def respond_based_on_content_type(request: Request, call_next):
|
||||
requested_path = request.url.path
|
||||
if requested_path in ["/docs", "/redoc", "/openapi.json"]:
|
||||
return await call_next(request)
|
||||
|
||||
try:
|
||||
response = await call_next(request)
|
||||
|
||||
user_agent = request.headers.get("user-agent", "").lower()
|
||||
referer = request.headers.get("referer", "")
|
||||
content_type = request.query_params.get(
|
||||
"content_type",
|
||||
request.headers.get("content-type", request.headers.get("Accept")),
|
||||
)
|
||||
if "raw" in content_type:
|
||||
return await call_next(request)
|
||||
if content_type == "*/*":
|
||||
content_type = None
|
||||
if ("/docs" in referer or "/redoc" in referer) and content_type is None:
|
||||
content_type = "application/json"
|
||||
elif is_browser_request(user_agent) and content_type is None:
|
||||
content_type = "text/html"
|
||||
elif is_rtf_request(user_agent) and content_type is None:
|
||||
content_type = "application/rtf"
|
||||
elif content_type is None:
|
||||
content_type = content_type or "application/json"
|
||||
|
||||
body = b"".join([chunk async for chunk in response.body_iterator])
|
||||
|
||||
data = body.decode("utf-8")
|
||||
|
||||
if response.status_code == 404:
|
||||
return handle_not_found(request, data)
|
||||
if response.status_code == 422:
|
||||
return response
|
||||
if str(response.status_code)[0] not in "123":
|
||||
return response
|
||||
|
||||
return await handle_response(request, data, content_type)
|
||||
# except TemplateNotFound:
|
||||
# return HTMLResponse(content="Template Not Found ", status_code=404)
|
||||
except StarletteHTTPException as exc:
|
||||
return HTMLResponse(
|
||||
content=f"Error {exc.status_code}: {exc.detail}",
|
||||
status_code=exc.status_code,
|
||||
)
|
||||
except RequestValidationError as exc:
|
||||
return JSONResponse(status_code=422, content={"detail": exc.errors()})
|
||||
except Exception as e:
|
||||
print(traceback.format_exc())
|
||||
return HTMLResponse(content=f"Internal Server Error: {str(e)}", status_code=500)
|
||||
|
||||
|
||||
async def handle_response(request: Request, data: str, content_type: str):
|
||||
json_data = json.loads(data)
|
||||
|
||||
template_name = getattr(request.state, "template_name", "default_template.html")
|
||||
|
||||
if content_type == "application/json":
|
||||
return JSONResponse(content=json_data)
|
||||
|
||||
elif content_type == "text/html":
|
||||
return templates.TemplateResponse(
|
||||
template_name, {"request": request, "data": json_data}
|
||||
)
|
||||
|
||||
elif content_type == "text/html-partial":
|
||||
return templates.TemplateResponse(
|
||||
template_name, {"request": request, "data": json_data}
|
||||
)
|
||||
|
||||
elif (
|
||||
content_type == "text/markdown"
|
||||
or content_type == "md"
|
||||
or content_type == "markdown"
|
||||
):
|
||||
import html2text
|
||||
|
||||
template = templates.get_template(template_name)
|
||||
html_content = template.render(data=json_data)
|
||||
markdown_content = html2text.html2text(html_content)
|
||||
return PlainTextResponse(content=markdown_content)
|
||||
|
||||
elif content_type == "text/plain":
|
||||
plain_text_content = format_json_as_plain_text(json_data)
|
||||
return PlainTextResponse(content=plain_text_content)
|
||||
|
||||
elif (
|
||||
content_type == "text/rich"
|
||||
or content_type == "text/rtf"
|
||||
or content_type == "application/rtf"
|
||||
):
|
||||
rich_text_content = format_json_as_rich_text(json_data, template_name)
|
||||
return PlainTextResponse(content=rich_text_content)
|
||||
|
||||
elif content_type == "image/png":
|
||||
template = templates.get_template(template_name)
|
||||
html_content = template.render(data=json_data)
|
||||
screenshot = get_screenshot(html_content)
|
||||
return Response(content=screenshot.getvalue(), media_type="image/png")
|
||||
|
||||
elif content_type == "application/pdf":
|
||||
template = templates.get_template(template_name)
|
||||
html_content = template.render(data=json_data)
|
||||
pdf = WeasyHTML(string=html_content).write_pdf()
|
||||
return Response(content=pdf, media_type="application/pdf")
|
||||
|
||||
return JSONResponse(content=json_data)
|
||||
42
src/fastapi_dynamic_response/zpages/router.py
Normal file
42
src/fastapi_dynamic_response/zpages/router.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
from fastapi import APIRouter, HTTPException, Request
|
||||
from fastapi_dynamic_response import globals
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/livez")
|
||||
async def livez(request: Request):
|
||||
"""
|
||||
Liveness probe endpoint.
|
||||
Returns 200 OK if the application is alive.
|
||||
"""
|
||||
request.state.template_name = "status.html"
|
||||
return {"status": "alive"}
|
||||
|
||||
|
||||
@router.get("/readyz")
|
||||
async def readyz(request: Request):
|
||||
"""
|
||||
Readiness probe endpoint.
|
||||
Returns 200 OK if the application is ready to receive traffic.
|
||||
Returns 503 Service Unavailable if not ready.
|
||||
"""
|
||||
request.state.template_name = "status.html"
|
||||
if globals.is_ready:
|
||||
return {"status": "ready"}
|
||||
else:
|
||||
raise HTTPException(status_code=503, detail="Not ready")
|
||||
|
||||
|
||||
@router.get("/healthz")
|
||||
async def healthz(request: Request):
|
||||
"""
|
||||
Health check endpoint.
|
||||
Returns 200 OK if the application is healthy and ready.
|
||||
Returns 503 Service Unavailable if not healthy.
|
||||
"""
|
||||
request.state.template_name = "status.html"
|
||||
if is_ready:
|
||||
return {"status": "healthy"}
|
||||
else:
|
||||
raise HTTPException(status_code=503, detail="Unhealthy")
|
||||
19
templates/404.html
Normal file
19
templates/404.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!-- index.html -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>404 {{ requested_path }} not found</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Page Not Found</h2>
|
||||
<hr>
|
||||
<h3>Suggestions</h3>
|
||||
<p>
|
||||
You're looking for {{ requested_path }}, but there's nothing here, here are some suggestions:
|
||||
</p>
|
||||
|
||||
{% for suggestion in suggestions %}
|
||||
<li><a href="{{ suggestion }}">{{ suggestion }}</a> </li>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
||||
24
templates/another_example.html
Normal file
24
templates/another_example.html
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<!-- index.html -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Example</h2>
|
||||
<p>
|
||||
{{ data.message }}
|
||||
</p>
|
||||
|
||||
<h3>Items</h3>
|
||||
<p>
|
||||
there are {{ data.get('items', [])|length }} items in the list
|
||||
</p>
|
||||
<ul>
|
||||
{% for item in data.get('items', []) %}
|
||||
<li>{{ item }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
18
templates/example.html
Normal file
18
templates/example.html
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<!-- index.html -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Example</h2>
|
||||
<p>
|
||||
{{ data.message }}
|
||||
</p>
|
||||
|
||||
<h3>Data</h3>
|
||||
|
||||
{{ data.data }}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
7
templates/post_message.html
Normal file
7
templates/post_message.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Message Received</title>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
13
templates/sitemap.html
Normal file
13
templates/sitemap.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>siemap</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Sitemap</h1>
|
||||
|
||||
{% for route in data.available_routes %}
|
||||
<li><a href="{{ route }}">{{ route }}</a> </li>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
||||
3
tests/__init__.py
Normal file
3
tests/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# SPDX-FileCopyrightText: 2024-present U.N. Owen <void@some.where>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
Loading…
Add table
Add a link
Reference in a new issue