def index() -> str: template_vars: Dict[str, str] = { "supported_extensions": ",".join(get_supported_extensions()), } printer_display_name = config.get_printer_display_name() if printer_display_name is not None: template_vars["printer_display_name"] = printer_display_name return render_template("index.html", **template_vars)
def run(self) -> None: os.nice(5) globs = [ FILES_DIRECTORY.rglob(f"*{extension}") for extension in get_supported_extensions() ] for file in chain.from_iterable(globs): read_cached_sliced_model_file(file.absolute()) read_cached_preview(file.absolute())
def run(self) -> None: os.nice(5) globs = [ config.get_files_directory().rglob(f"*{extension}") for extension in get_supported_extensions() ] for file in chain.from_iterable(globs): read_cached_sliced_model_file(file.absolute()) read_cached_preview(file.absolute())
def upload_file() -> str: file = request.files.get("file") if file is None or file.filename == "": abort(400) if os.path.splitext(file.filename)[1] not in get_supported_extensions(): abort(400) filename = secure_filename(file.filename) file.save(str(config.get_files_directory() / filename)) os.sync() return jsonify({"success": True})
def list_files() -> str: path_parameter = str(request.args.get("path", ".")) path = (config.get_files_directory() / path_parameter).resolve() if ( config.get_files_directory() not in path.parents and path != config.get_files_directory() ): abort(400) with os.scandir(path) as dir_entries: files = [] directories = [] for dir_entry in sorted( dir_entries, key=lambda t: t.stat().st_mtime, reverse=True ): if dir_entry.is_file(): sliced_model_file: Optional[SlicedModelFile] = None if dir_entry.name.endswith(tuple(get_supported_extensions())): sliced_model_file = read_cached_sliced_model_file( path / dir_entry.name ) file_data: Dict[str, Any] = { "filename": dir_entry.name, "path": str( (path / dir_entry.name).relative_to( config.get_files_directory() ) ), } if sliced_model_file: file_data = { "print_time_secs": sliced_model_file.print_time_secs, "can_be_printed": True, **file_data, } else: file_data = { "can_be_printed": False, **file_data, } files.append(file_data) else: directories.append({"dirname": dir_entry.name}) return jsonify( { "directories": directories, "files": files, } )
def index() -> str: return render_template("index.html", supported_extensions=",".join( get_supported_extensions()))