From fc336b661f8f5580c93262adc469c8cd38e98c4d Mon Sep 17 00:00:00 2001 From: night0721 <night@night0721.xyz> Date: Thu, 16 Jan 2025 10:59:30 +0000 Subject: [PATCH] Add imports --- index.html | 2 +- sfb.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index d74e799..7564462 100644 --- a/index.html +++ b/index.html @@ -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> diff --git a/sfb.py b/sfb.py index 9011f57..b80fb40 100644 --- a/sfb.py +++ b/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()