fixing upload...

This commit is contained in:
tonyrewin 2023-01-10 10:48:59 +03:00
parent c0fbfc29ab
commit 97d30f155d
6 changed files with 52 additions and 32 deletions

View File

@ -1,3 +1,8 @@
[0.7.1]
[+] reactions CRUL
[+] upload with storj
[0.7.0]
[+] inbox: context provider, chats
[+] comments: show

View File

@ -1,4 +1,4 @@
from flask import Flask, request
from flask import Flask, request, jsonify
from werkzeug.utils import secure_filename
import boto3
from botocore.exceptions import ClientError, WaiterError
@ -17,7 +17,7 @@ storj_client = boto3.client('s3',
def upload_storj(filecontent, filename, bucket_name):
head = None
bucket_obj = None
try:
bucket = storj_resource.Bucket(bucket_name)
except ClientError:
@ -33,22 +33,22 @@ def upload_storj(filecontent, filename, bucket_name):
etag = head['ETag'].strip('"')
try:
s3_obj = bucket.Object(filename)
bucket_obj = bucket.Object(filename)
except (ClientError, AttributeError):
s3_obj = None
bucket_obj = None
try:
# Use the upload_fileobj method to safely upload the file
storj_client.upload_fileobj(
Fileobj=filecontent,
Bucket='discours.io',
Bucket=bucket_name,
Key=filename
)
except (ClientError, AttributeError):
pass
else:
try:
s3_obj.wait_until_exists(IfNoneMatch=etag)
bucket_obj.wait_until_exists(IfNoneMatch=etag)
except WaiterError:
pass
else:
@ -56,22 +56,21 @@ def upload_storj(filecontent, filename, bucket_name):
return head
@app.route('/upload', methods=['post'])
@app.route('/api/upload', methods=['post'])
def upload():
if request.method == 'POST':
img = request.files['file']
if img:
# Perform the file upload
filename = secure_filename(img.filename)
# Save the file to a temporary location
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = os.path.join(temp_dir, filename)
img.save(temp_path)
# Open the file in binary mode
with open(temp_path, 'rb') as filecontent:
return upload_storj(filecontent, filename, 'discours.io')
print('upload serverless route is fine')
print(request.path)
print(request.form)
print(request.files)
img = request.files['file']
if img:
# Perform the file upload
filename = secure_filename(img.filename)
# Save the file to a temporary location
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = os.path.join(temp_dir, filename)
img.save(temp_path)
# Open the file in binary mode
with open(temp_path, 'rb') as filecontent:
return jsonify(upload_storj(filecontent, filename, 'discoursio'))
return
if __name__ == "__main__":
app.run()

View File

@ -37,6 +37,7 @@ export const ProfileSettingsPage = (props: PageProps) => {
formData.append('type', file.type)
formData.append('name', image.source.split('/').pop())
formData.append('ext', image.name.split('.').pop())
formData.append('data', image.file)
const resp = await fetch('/api/upload', {
method: 'POST',
body: formData

View File

@ -4,18 +4,19 @@
.popup {
background: #fff;
top: calc(100% + 8px);
opacity: 1;
color: #000;
position: absolute;
z-index: 100;
min-width: 144px;
opacity: 1;
position: absolute;
top: calc(100% + 8px);
z-index: 100;
ul {
margin-bottom: 0;
li {
position: relative;
&:last-child {
margin-bottom: 0;
}
@ -24,11 +25,12 @@
&.bordered {
@include font-size(1.6rem);
border: 2px solid #000;
padding: 2.4rem;
ul li {
margin-bottom: 1.6rem;
&:last-child {
margin-bottom: 0;
}
@ -37,11 +39,12 @@
&.tiny {
@include font-size(1.4rem);
box-shadow: 0 4px 60px rgba(0, 0, 0, 0.1);
padding: 1rem;
ul li {
margin-bottom: 1rem;
&:last-child {
margin-bottom: 0;
}

View File

@ -4,8 +4,20 @@ import Prerendered from '../main.astro'
import { apiClient } from '../utils/apiClient'
import { initRouter } from '../stores/router'
const excludes = [
'authors',
'connect',
'create',
'inbox',
'search',
'topics',
'welcome',
'confirm',
'feed'
]
const slug = Astro.params.slug?.toString()
if (slug.endsWith('.map')) {
if (slug.endsWith('.map') || slug in excludes) {
return Astro.redirect('/404')
}

View File

@ -12,8 +12,8 @@ import type {
MutationCreateMessageArgs,
Chat,
QueryLoadRecipientsArgs,
ReactionBy,
ProfileInput
ProfileInput,
ReactionBy
} from '../graphql/types.gen'
import { publicGraphQLClient } from '../graphql/publicGraphQLClient'
import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient'