Fix all paths to be absolute based on __file__ to work regardless of working directory
- Make RESULTS_DIR, SESSION_FILE_DIR, uploads absolute - Add error handling around file saving with detailed logging - Add /test route to check write permissions - Ensure app works on remote with correct paths and permissions
This commit is contained in:
1 parent
95a74e9035
commit
3215cd9032
1 file changed
+26
-13
@@ -33,14 +33,14 @@ app.config['MAX_CONTENT_LENGTH'] = 1000 * 1024 * 1024 * 1024 # 1000TB
|
||||
|
||||
# Configure server-side sessions to avoid cookie size limits
|
||||
app.config['SESSION_TYPE'] = 'filesystem'
|
||||
app.config['SESSION_FILE_DIR'] = 'sessions'
|
||||
app.config['SESSION_FILE_DIR'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'sessions'))
|
||||
app.config['SESSION_PERMANENT'] = False
|
||||
|
||||
# Ensure session directory exists and is writable
|
||||
os.makedirs('sessions', exist_ok=True)
|
||||
|
||||
# Ensure uploads directory exists
|
||||
os.makedirs('uploads', exist_ok=True)
|
||||
os.makedirs(os.path.abspath(os.path.join(os.path.dirname(__file__), 'uploads')), exist_ok=True)
|
||||
|
||||
try:
|
||||
Session(app)
|
||||
@@ -270,7 +270,7 @@ def logout():
|
||||
|
||||
# Job storage
|
||||
JOBS_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), 'jobs.json'))
|
||||
RESULTS_DIR = os.path.abspath('results')
|
||||
RESULTS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'results'))
|
||||
os.makedirs(RESULTS_DIR, exist_ok=True)
|
||||
|
||||
processing_complete = False
|
||||
@@ -350,9 +350,9 @@ def save_jobs(jobs):
|
||||
print(f"Error saving jobs: {e}")
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
# @login_required # Temporarily disabled for debugging
|
||||
@login_required
|
||||
def index():
|
||||
print(f"DEBUG: index() called WITHOUT login_required")
|
||||
print(f"DEBUG: index() called with method={request.method}")
|
||||
global processing_complete, current_output_dir
|
||||
if request.method == 'POST':
|
||||
print(f"POST request received at {datetime.now()}")
|
||||
@@ -369,13 +369,14 @@ def index():
|
||||
job_id = job_start_time.strftime('%Y%m%d_%H%M%S')
|
||||
|
||||
# Create dirs
|
||||
input_dir = os.path.join('uploads', job_id)
|
||||
input_dir = os.path.join(os.path.dirname(__file__), 'uploads', job_id)
|
||||
os.makedirs(input_dir, exist_ok=True)
|
||||
output_dir = tempfile.mkdtemp()
|
||||
current_output_dir = output_dir
|
||||
|
||||
for file in files:
|
||||
if file and file.filename:
|
||||
try:
|
||||
filename = secure_filename(file.filename)
|
||||
if filename.endswith('.zip'):
|
||||
# Extract zip
|
||||
@@ -387,13 +388,18 @@ def index():
|
||||
shutil.rmtree(zip_temp)
|
||||
print(f"Extracted ZIP: {filename}")
|
||||
elif filename.endswith('.pdf'):
|
||||
file.save(os.path.join(input_dir, filename))
|
||||
print(f"Saved PDF: {filename}")
|
||||
# For folder upload, files are saved with secure_filename, but since webkitdirectory, filename includes path, but secure_filename flattens it
|
||||
file_path = os.path.join(input_dir, filename)
|
||||
file.save(file_path)
|
||||
print(f"Saved PDF: {filename} to {file_path}")
|
||||
else:
|
||||
# Assume folder upload
|
||||
file.save(os.path.join(input_dir, filename))
|
||||
print(f"Saved file from folder: {filename}")
|
||||
file_path = os.path.join(input_dir, filename)
|
||||
file.save(file_path)
|
||||
print(f"Saved file from folder: {filename} to {file_path}")
|
||||
except Exception as e:
|
||||
print(f"Error saving file {file.filename}: {e}")
|
||||
flash(f'Error saving file {file.filename}: {e}')
|
||||
return redirect(request.url)
|
||||
|
||||
# Create job immediately
|
||||
jobs = load_jobs()
|
||||
@@ -419,8 +425,15 @@ def index():
|
||||
|
||||
return render_template('index.html', user_info=get_user_info())
|
||||
|
||||
@app.route('/status')
|
||||
def status():
|
||||
@app.route('/test')
|
||||
def test():
|
||||
try:
|
||||
test_file = os.path.join(os.path.dirname(__file__), 'uploads', 'test.txt')
|
||||
with open(test_file, 'w') as f:
|
||||
f.write('test')
|
||||
return f'Test file created at {test_file}'
|
||||
except Exception as e:
|
||||
return f'Error: {e}'
|
||||
print("Status requested")
|
||||
try:
|
||||
with open('status.txt', 'r') as f:
|
||||
|
||||
Reference in new issue
Block a user