Untitled

 avatar
user_4523866
plain_text
6 months ago
2.1 kB
5
Indexable
from flask import Flask, request, jsonify, render_template
from vfs_core_advanced import VFSCoreAdvanced
from vfs_metadata_cache_advanced import MetadataManagerAdvanced, CacheManagerAdvanced

app = Flask(__name__)
vfs = VFSCoreAdvanced()
metadata_manager = MetadataManagerAdvanced()
cache_manager = CacheManagerAdvanced()

@app.route('/')
def home():
    return render_template("index.html")  # Simple HTML template for interaction

@app.route('/create', methods=['POST'])
def create_file():
    file_path = request.form['path']
    content = request.form.get('content', "")
    vfs.create_file(file_path, content)
    metadata_manager.update_metadata(file_path)
    return jsonify({"message": f"File '{file_path}' created successfully."})

@app.route('/read', methods=['GET'])
def read_file():
    file_path = request.args['path']
    content = cache_manager.get_from_cache(file_path)
    if content is None:
        content = vfs.read_file(file_path)
        cache_manager.add_to_cache(file_path, content)
    metadata_manager.increment_access_count(file_path)
    return jsonify({"content": content})

@app.route('/update', methods=['POST'])
def update_file():
    file_path = request.form['path']
    content = request.form['content']
    vfs.update_file(file_path, content)
    metadata_manager.update_metadata(file_path)
    cache_manager.add_to_cache(file_path, content)
    return jsonify({"message": f"File '{file_path}' updated successfully."})

@app.route('/delete', methods=['POST'])
def delete_file():
    file_path = request.form['path']
    vfs.delete_file(file_path)
    metadata_manager.update_metadata(file_path)
    return jsonify({"message": f"File '{file_path}' deleted successfully."})

@app.route('/move', methods=['POST'])
def move_file():
    src_path = request.form['src']
    dest_path = request.form['dest']
    vfs.move_file(src_path, dest_path)
    metadata_manager.update_metadata(dest_path)
    return jsonify({"message": f"File moved from '{src_path}' to '{dest_path}'."})

if __name__ == "__main__":
    app.run(debug=True)
Editor is loading...
Leave a Comment