Add imports
This commit is contained in:
parent
ea9ddf3e41
commit
fc336b661f
2 changed files with 6 additions and 5 deletions
|
@ -48,7 +48,7 @@
|
|||
<pre>Temporary file hoster.</pre>
|
||||
<pre>You can either enter text below and click submit to create a link or use CURL/other http client to send POST request for creating links</pre>
|
||||
<pre>CURL example:</pre>
|
||||
<code>curl -F'file=@yourfile.png' bin.night0721.xyz</code>
|
||||
<code>curl -F'file=@yourfile.png' https://bin.night0721.xyz</code>
|
||||
<pre>Server will responde with a URL to your file, e.g. https://bin.night0721.xyz/abcd</pre>
|
||||
<textarea id="pasteContent" placeholder="Type or paste your content here..."></textarea>
|
||||
<button onclick="submitPaste()">Submit</button>
|
||||
|
|
9
sfb.py
9
sfb.py
|
@ -1,9 +1,12 @@
|
|||
from flask import Flask, request, jsonify, send_from_directory, send_file
|
||||
from flask import Flask, request, jsonify, send_from_directory, send_file, render_template_string
|
||||
from flask_cors import CORS, cross_origin
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
from datetime import datetime
|
||||
from pygments import highlight
|
||||
from pygments.lexers import guess_lexer
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
# Configuration
|
||||
OUTPUT_DIR = "code"
|
||||
|
@ -81,13 +84,11 @@ HTML_TEMPLATE = """
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ id }}</title>
|
||||
<style>
|
||||
{{ style }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>File: {{ id }}</h1>
|
||||
<pre>{{ content|safe }}</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -103,7 +104,7 @@ def get_file_raw(id):
|
|||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
content = file.read()
|
||||
lexer = guess_lexer_for_filename(file_path, content)
|
||||
lexer = guess_lexer(content)
|
||||
formatter = HtmlFormatter()
|
||||
highlighted_content = highlight(content, lexer, formatter)
|
||||
style = formatter.get_style_defs()
|
||||
|
|
Loading…
Reference in a new issue