Fix local file upload

This commit is contained in:
Julien Nahum 2024-01-13 18:17:24 +01:00
parent ff7e1ac7c3
commit bf98497711
9 changed files with 18 additions and 48 deletions

View File

@ -17,6 +17,7 @@ class FileUploadController extends Controller
*/ */
public function upload(Request $request) public function upload(Request $request)
{ {
$request->validate(['file' => 'required|file']);
$uuid = (string) Str::uuid(); $uuid = (string) Str::uuid();
$path = $request->file('file')->storeAs(PublicFormController::TMP_FILE_UPLOAD_PATH, $uuid); $path = $request->file('file')->storeAs(PublicFormController::TMP_FILE_UPLOAD_PATH, $uuid);

View File

@ -19,15 +19,6 @@ class RouteServiceProvider extends ServiceProvider
*/ */
public const HOME = '/home'; public const HOME = '/home';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/** /**
* Define your route model bindings, pattern filters, etc. * Define your route model bindings, pattern filters, etc.
* *
@ -39,14 +30,9 @@ class RouteServiceProvider extends ServiceProvider
$this->registerGlobalRouteParamConstraints(); $this->registerGlobalRouteParamConstraints();
$this->routes(function () { $this->routes(function () {
Route::middleware('api') Route::middleware('api')
->namespace($this->namespace) ->namespace($this->namespace)
->group(base_path('routes/api.php')); ->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}); });
} }

View File

@ -221,7 +221,6 @@ export default {
methods: { methods: {
displayFormModificationAlert (responseData) { displayFormModificationAlert (responseData) {
const alert = useAlert() const alert = useAlert()
console.log("in okd ----.", responseData)
if (responseData.form && responseData.form.cleanings && Object.keys(responseData.form.cleanings).length > 0) { if (responseData.form && responseData.form.cleanings && Object.keys(responseData.form.cleanings).length > 0) {
alert.warning(responseData.message) alert.warning(responseData.message)
} else if (responseData.message) { } else if (responseData.message) {

View File

@ -58,7 +58,7 @@ export const useCrisp = () => {
}); });
if (user?.is_subscribed ?? false) { if (user?.is_subscribed ?? false) {
setSegments([['subscribed', user?.has_enterprise_subscription ? 'enterprise' : 'pro']]) setSegments(['subscribed', user?.has_enterprise_subscription ? 'enterprise' : 'pro'])
} }
} }

View File

@ -9,7 +9,7 @@ function addAuthHeader(request, options) {
function addPasswordToFormRequest(request, options) { function addPasswordToFormRequest(request, options) {
const url = request.url const url = request.url
if (!url || !url.startsWith('/api/forms/')) return if (!url || !url.startsWith('/forms/')) return
const slug = url.split('/')[3] const slug = url.split('/')[3]
const passwordCookie = useCookie('password-' + slug, {maxAge: 60 * 60 * 24 * 30}) // 30 days const passwordCookie = useCookie('password-' + slug, {maxAge: 60 * 60 * 24 * 30}) // 30 days
@ -29,6 +29,13 @@ function addCustomDomainHeader(request, options) {
export function getOpnRequestsOptions(request, opts) { export function getOpnRequestsOptions(request, opts) {
const config = useRuntimeConfig() const config = useRuntimeConfig()
if (opts.body && opts.body instanceof FormData) {
opts.headers = {
'charset': 'utf-8',
...opts.headers,
}
}
opts.headers = {accept: 'application/json', ...opts.headers} opts.headers = {accept: 'application/json', ...opts.headers}
// Authenticate requests coming from the server // Authenticate requests coming from the server

View File

@ -6,9 +6,6 @@ export const storeFile = async (file, options = {}) => {
formData.append('file', file) formData.append('file', file)
const response = await useOpnApi('/upload-file', { const response = await useOpnApi('/upload-file', {
method: 'POST', method: 'POST',
headers: {
'Content-Type': 'multipart/form-data'
},
body: formData body: formData
}) })
response.data.extension = file.name.split('.').pop() response.data.extension = file.name.split('.').pop()
@ -26,7 +23,8 @@ export const storeFile = async (file, options = {}) => {
headers: options.headers || {}, headers: options.headers || {},
...options.options ...options.options
}) })
console.log("response.data",response.data)
console.log(response)
const headers = response.data.headers const headers = response.data.headers
@ -38,17 +36,11 @@ export const storeFile = async (file, options = {}) => {
options.progress = () => {} options.progress = () => {}
} }
const cancelToken = options.cancelToken || '' // Upload to S3
await useFetch(response.data.url,{
// Remove authorization headers method: 'PUT',
const cleanAxios = axios.create() body: file,
cleanAxios.defaults.headers.common = {}
await cleanAxios.put(response.data.url, file, {
cancelToken: cancelToken,
headers: headers, headers: headers,
onUploadProgress: (progressEvent) => {
options.progress(progressEvent.loaded / progressEvent.total)
}
}) })
response.data.extension = file.name.split('.').pop() response.data.extension = file.name.split('.').pop()

View File

@ -32,6 +32,7 @@ export default defineNuxtConfig({
}, },
sentry: { sentry: {
dsn: process.env.NUXT_PUBLIC_SENTRY_DSN, dsn: process.env.NUXT_PUBLIC_SENTRY_DSN,
lazy: true,
}, },
components: [ components: [
{ {

View File

@ -181,8 +181,6 @@ Route::prefix('templates')->group(function () {
Route::delete('/{id}', [TemplateController::class, 'destroy'])->name('templates.destroy'); Route::delete('/{id}', [TemplateController::class, 'destroy'])->name('templates.destroy');
}); });
Route::post( Route::post(
'/stripe/webhook', '/stripe/webhook',
[\App\Http\Controllers\Webhook\StripeController::class, 'handleWebhook'] [\App\Http\Controllers\Webhook\StripeController::class, 'handleWebhook']

View File

@ -1,14 +0,0 @@
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/