setup env.example file
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
# Supabase setup - Required
|
||||||
|
PUBLIC_SUPABASE_URL=http://localhost:54321
|
||||||
|
PUBLIC_SUPABASE_BUCKET_URL=http://localhost:54323
|
||||||
|
PUBLIC_SUPABASE_ANON_KEY=
|
||||||
|
|
||||||
|
# Email setup - Optional if you want to get/send emails
|
||||||
|
SMTP_PASSWORD_HELP=
|
||||||
|
SMTP_USER_HELP=
|
||||||
|
SMTP_HOST=
|
||||||
|
SMTP_USER=
|
||||||
|
SMTP_PASSWORD=
|
||||||
|
|
||||||
|
# Unsplash setup - Optional if you want to use Unsplash images
|
||||||
|
UNSPLASH_API_KEY=lIAS15EsfVk4wkIBEIXGbSugzgTVK-c1qRb8VlNEl1c
|
||||||
|
|
||||||
|
PUBLIC_TINYMCE_API_KEY=jrxdl8ku7f7blb1wg98erwak5c3754orv3xpjic2nhimns4j
|
||||||
|
|
||||||
|
|
||||||
|
VITE_SENTRY_AUTH_TOKEN=c352344ad44b6fcd84316cf451e52521d479abc0b692db1de3d29ffdf17ce221
|
||||||
|
VITE_SENTRY_ORG_NAME=the-next-greats
|
||||||
|
VITE_SENTRY_PROJECT_NAME=classroomio
|
||||||
|
|
||||||
|
# OpenAI setup - Optional if you want to use OpenAI
|
||||||
|
OPENAI_API_KEY=
|
||||||
@@ -1,22 +1,4 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
||||||
|
|
||||||
import {
|
|
||||||
CLOUDFLARE_ACCESS_KEY,
|
|
||||||
CLOUDFLARE_SECRET_ACCESS_KEY,
|
|
||||||
CLOUDFLARE_ACCOUNT_ID,
|
|
||||||
CLOUDFLARE_PUBLIC_ACCOUNT_ID,
|
|
||||||
MUSE_API_KEY
|
|
||||||
} from '$env/static/private';
|
|
||||||
|
|
||||||
const S3 = new S3Client({
|
|
||||||
region: 'auto',
|
|
||||||
endpoint: `https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
||||||
credentials: {
|
|
||||||
accessKeyId: CLOUDFLARE_ACCESS_KEY,
|
|
||||||
secretAccessKey: CLOUDFLARE_SECRET_ACCESS_KEY
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const downloadTranscript = async () => {};
|
const downloadTranscript = async () => {};
|
||||||
|
|
||||||
|
|||||||
@@ -1,97 +1,7 @@
|
|||||||
/**
|
|
||||||
* This code isn't used anymore due to vercels 4.5MB limit of file sizes
|
|
||||||
* I will leave it here for reference and learning purposes
|
|
||||||
* The code has now been moved to classroomio-server, our express.js backend
|
|
||||||
*
|
|
||||||
* Read more: https://vercel.com/guides/how-to-bypass-vercel-body-size-limit-serverless-functions
|
|
||||||
* */
|
|
||||||
import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
||||||
import FormData from 'form-data';
|
|
||||||
import axios from 'axios';
|
|
||||||
import { fail } from '@sveltejs/kit';
|
|
||||||
import genUniqueId from '$lib/utils/functions/genUniqueId.js';
|
|
||||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
|
||||||
|
|
||||||
import {
|
|
||||||
CLOUDFLARE_ACCESS_KEY,
|
|
||||||
CLOUDFLARE_SECRET_ACCESS_KEY,
|
|
||||||
CLOUDFLARE_ACCOUNT_ID,
|
|
||||||
CLOUDFLARE_PUBLIC_ACCOUNT_ID,
|
|
||||||
MUSE_API_KEY
|
|
||||||
} from '$env/static/private';
|
|
||||||
|
|
||||||
// Set the runtime to edge for best performance
|
|
||||||
export const config = {
|
|
||||||
runtime: 'edge'
|
|
||||||
};
|
|
||||||
|
|
||||||
const S3 = new S3Client({
|
|
||||||
region: 'auto',
|
|
||||||
endpoint: `https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
||||||
credentials: {
|
|
||||||
accessKeyId: CLOUDFLARE_ACCESS_KEY,
|
|
||||||
secretAccessKey: CLOUDFLARE_SECRET_ACCESS_KEY
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const supabase = getSupabase();
|
|
||||||
|
|
||||||
const uploadToMuse = (s3Data, fileName, lessonId, fileUrl) => {
|
|
||||||
try {
|
|
||||||
const form = new FormData();
|
|
||||||
form.append('file', s3Data, fileName);
|
|
||||||
|
|
||||||
axios({
|
|
||||||
method: 'POST',
|
|
||||||
url: 'https://api.muse.ai/api/files/upload',
|
|
||||||
data: form,
|
|
||||||
maxContentLength: Infinity,
|
|
||||||
maxBodyLength: Infinity,
|
|
||||||
headers: {
|
|
||||||
Key: MUSE_API_KEY
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(async function (response) {
|
|
||||||
console.log('Upload to muse complete', response.data);
|
|
||||||
|
|
||||||
const { data: lesson } = await supabase
|
|
||||||
.from('lesson')
|
|
||||||
.select(`*`)
|
|
||||||
.eq('id', lessonId)
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (lesson) {
|
|
||||||
// Add Muse response to metadata
|
|
||||||
const videos = lesson.videos.map((v) => {
|
|
||||||
if (v.link === fileUrl) {
|
|
||||||
console.log('matches');
|
|
||||||
v.metadata = JSON.parse(JSON.stringify(response.data));
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
});
|
|
||||||
|
|
||||||
const { error, data } = await supabase
|
|
||||||
.from('lesson')
|
|
||||||
.update({ videos })
|
|
||||||
.eq('id', lessonId)
|
|
||||||
.select();
|
|
||||||
if (error) {
|
|
||||||
console.log('Error updating lesson', error);
|
|
||||||
}
|
|
||||||
console.log('update data', data);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
console.log('Upload to Muse failed', error);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.log('Upload to Muse failed', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const load = ({ params = { id: '' } }) => {
|
export const load = ({ params = { id: '' } }) => {
|
||||||
const { id: courseId, lessonParams = [] } = params;
|
const { id: courseId, lessonParams = '' } = params;
|
||||||
const splitparams = lessonParams.split('/');
|
const splitparams = lessonParams.split('/');
|
||||||
|
|
||||||
const [lessonId, exerciseRouteName, exerciseId] = splitparams;
|
const [lessonId, exerciseRouteName, exerciseId] = splitparams;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -102,73 +12,3 @@ export const load = ({ params = { id: '' } }) => {
|
|||||||
isMaterialsTabActive: !exerciseRouteName
|
isMaterialsTabActive: !exerciseRouteName
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
|
||||||
create: async ({ request }) => {
|
|
||||||
const formData = Object.fromEntries(await request.formData());
|
|
||||||
console.log('formData', formData);
|
|
||||||
|
|
||||||
if (!formData.file?.name || formData.file?.name === 'undefined') {
|
|
||||||
return fail(400, {
|
|
||||||
success: false,
|
|
||||||
message: 'You must provide a file to upload'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formData.file?.size > 20 * 1024 * 1024) {
|
|
||||||
return fail(400, {
|
|
||||||
success: false,
|
|
||||||
type: 'FILE_TOO_LARGE',
|
|
||||||
message: 'File is too large'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const { file, lessonId } = formData;
|
|
||||||
console.log('file', file);
|
|
||||||
console.log('lessonId', lessonId);
|
|
||||||
|
|
||||||
const stream = await file.arrayBuffer();
|
|
||||||
const fileName = `${genUniqueId()}-${file.name}`;
|
|
||||||
const params = {
|
|
||||||
Bucket: 'videos',
|
|
||||||
Key: fileName,
|
|
||||||
Body: stream,
|
|
||||||
ContentLength: stream.length
|
|
||||||
};
|
|
||||||
console.log('params', params);
|
|
||||||
|
|
||||||
let upload;
|
|
||||||
|
|
||||||
const fileUrl = `https://pub-${CLOUDFLARE_PUBLIC_ACCOUNT_ID}.r2.dev/${fileName}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
upload = await S3.send(new PutObjectCommand(params));
|
|
||||||
// process data.
|
|
||||||
} catch (error) {
|
|
||||||
// error handling.
|
|
||||||
const { requestId, cfId, extendedRequestId } = error.$$metadata;
|
|
||||||
console.error('Error uploading file');
|
|
||||||
console.log({ requestId, cfId, extendedRequestId });
|
|
||||||
} finally {
|
|
||||||
// finally.
|
|
||||||
console.log('File upload complete', upload);
|
|
||||||
|
|
||||||
console.log('\n\nInitilizing Muse Request');
|
|
||||||
|
|
||||||
const data = await S3.send(
|
|
||||||
new GetObjectCommand({
|
|
||||||
Bucket: 'videos',
|
|
||||||
Key: fileName
|
|
||||||
})
|
|
||||||
);
|
|
||||||
// console.log('GetObjectCommand', data);
|
|
||||||
uploadToMuse(data.Body, file.name, lessonId, fileUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
url: fileUrl,
|
|
||||||
message: 'Uploaded successfully'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
+11
-6
@@ -4,16 +4,21 @@ import { defineConfig, loadEnv } from 'vite';
|
|||||||
|
|
||||||
export default ({ mode }) => {
|
export default ({ mode }) => {
|
||||||
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
|
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
|
||||||
|
const { VITE_SENTRY_AUTH_TOKEN, VITE_SENTRY_ORG_NAME, VITE_SENTRY_PROJECT_NAME } = process.env;
|
||||||
|
|
||||||
return defineConfig({
|
return defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
sveltekit(),
|
sveltekit(),
|
||||||
sentryVitePlugin({
|
sentryVitePlugin(
|
||||||
url: 'https://sentry.io',
|
VITE_SENTRY_AUTH_TOKEN
|
||||||
authToken: process.env.VITE_SENTRY_AUTH_TOKEN,
|
? {
|
||||||
org: 'the-next-greats',
|
url: 'https://sentry.io',
|
||||||
project: 'classroomio'
|
authToken: VITE_SENTRY_AUTH_TOKEN,
|
||||||
})
|
org: VITE_SENTRY_ORG_NAME,
|
||||||
|
project: VITE_SENTRY_PROJECT_NAME
|
||||||
|
}
|
||||||
|
: {}
|
||||||
|
)
|
||||||
],
|
],
|
||||||
build: {
|
build: {
|
||||||
sourcemap: true
|
sourcemap: true
|
||||||
|
|||||||
Reference in New Issue
Block a user