From 42e1da4aa5e9085c7052596a7734ae388d9273bf Mon Sep 17 00:00:00 2001
From: vincanger <70215737+vincanger@users.noreply.github.com>
Date: Mon, 5 Feb 2024 17:09:46 -0500
Subject: [PATCH] add file upload page & actions
improve fetching download url
---
app/.env.server.example | 8 +-
app/.prettierrc | 3 +-
app/main.wasp | 37 +++++-
app/src/client/app/DemoAppPage.tsx | 4 +-
app/src/client/app/FileUploadPage.tsx | 129 +++++++++++++++++++
app/src/client/components/AppNavBar.tsx | 1 +
app/src/server/actions.ts | 58 +++++++--
app/src/server/file-upload/s3Utils.ts | 39 ++++++
app/src/server/{ => payments}/stripeUtils.ts | 0
app/src/server/queries.ts | 36 +++++-
10 files changed, 297 insertions(+), 18 deletions(-)
create mode 100644 app/src/client/app/FileUploadPage.tsx
create mode 100644 app/src/server/file-upload/s3Utils.ts
rename app/src/server/{ => payments}/stripeUtils.ts (100%)
diff --git a/app/.env.server.example b/app/.env.server.example
index 5fda680..7f99181 100644
--- a/app/.env.server.example
+++ b/app/.env.server.example
@@ -37,4 +37,10 @@ GOOGLE_ANALYTICS_CLIENT_EMAIL=email@example.gserviceaccount.com
# Make sure you convert the private key within the JSON file to base64 first with `echo -n "PRIVATE_KEY" | base64`. see the docs for more info.
GOOGLE_ANALYTICS_PRIVATE_KEY=LS02...
# You will find your Property ID in the Google Analytics dashboard. It will look like '987654321'
-GOOGLE_ANALYTICS_PROPERTY_ID=123456789
\ No newline at end of file
+GOOGLE_ANALYTICS_PROPERTY_ID=123456789
+
+# (OPTIONAL) get your aws s3 credentials at https://console.aws.amazon.com and create a new IAM user with S3 access
+AWS_S3_IAM_ACCESS_KEY=ACK...
+AWS_S3_IAM_SECRET_KEY=t+33a...
+AWS_S3_FILES_BUCKET=your-bucket-name
+AWS_S3_REGION=your-region
\ No newline at end of file
diff --git a/app/.prettierrc b/app/.prettierrc
index 2b3e125..8fa71eb 100644
--- a/app/.prettierrc
+++ b/app/.prettierrc
@@ -4,5 +4,6 @@
"singleQuote": true,
"endOfLine": "lf",
"tabWidth": 2,
- "jsxSingleQuote": true
+ "jsxSingleQuote": true,
+ "printWidth": 120
}
diff --git a/app/main.wasp b/app/main.wasp
index 57187e9..d13c43d 100644
--- a/app/main.wasp
+++ b/app/main.wasp
@@ -85,7 +85,8 @@ app SaaSTemplate {
("openai", "^4.24.1"),
("prettier", "3.1.1"),
("prettier-plugin-tailwindcss", "0.5.11"),
- ("zod", "3.22.4")
+ ("zod", "3.22.4"),
+ ("aws-sdk", "^2.1551.0")
],
}
@@ -116,6 +117,7 @@ entity User {=psl
externalAuthAssociations SocialLogin[]
contactFormMessages ContactFormMessage[]
tasks Task[]
+ files File[]
psl=}
entity SocialLogin {=psl
@@ -147,6 +149,17 @@ entity Task {=psl
createdAt DateTime @default(now())
psl=}
+entity File {=psl
+ id String @id @default(uuid())
+ name String
+ type String
+ key String
+ uploadUrl String
+ user User @relation(fields: [userId], references: [id])
+ userId Int
+ createdAt DateTime @default(now())
+psl=}
+
// TODO: add functionality to allow users to send messages to admin
// and make them accessible via the admin dashboard
entity ContactFormMessage {=psl
@@ -246,6 +259,12 @@ page CheckoutPage {
component: import Checkout from "@client/app/CheckoutPage"
}
+route FileUploadRoute { path: "/file-upload", to: FileUploadPage }
+page FileUploadPage {
+ authRequired: true,
+ component: import FileUpload from "@client/app/FileUploadPage"
+}
+
route AdminRoute { path: "/admin", to: DashboardPage }
page DashboardPage {
authRequired: true,
@@ -347,6 +366,12 @@ action updateUserById {
entities: [User]
}
+action createFile {
+ fn: import { createFile } from "@server/actions.js",
+ entities: [User, File]
+}
+
+
// 📚 Queries
query getGptResponses {
@@ -359,6 +384,16 @@ query getAllTasksByUser {
entities: [Task]
}
+query getAllFilesByUser {
+ fn: import { getAllFilesByUser } from "@server/queries.js",
+ entities: [User, File]
+}
+
+query getDownloadFileSignedURL {
+ fn: import { getDownloadFileSignedURL } from "@server/queries.js",
+ entities: [User, File]
+}
+
query getDailyStats {
fn: import { getDailyStats } from "@server/queries.js",
entities: [User, DailyStats]
diff --git a/app/src/client/app/DemoAppPage.tsx b/app/src/client/app/DemoAppPage.tsx
index e3618a6..ea00d7d 100644
--- a/app/src/client/app/DemoAppPage.tsx
+++ b/app/src/client/app/DemoAppPage.tsx
@@ -11,7 +11,7 @@ import { TiDelete } from 'react-icons/ti';
export default function DemoAppPage() {
return (
-
+
@@ -19,7 +19,7 @@ export default function DemoAppPage() {
- Enter your day's tasks and let AI do the rest!
+ This example app uses OpenAI's chat completions with function calling to return a structured JSON object. Try it out, enter your day's tasks, and let AI do the rest!
+ This is an example file upload page using AWS S3. Maybe your app needs this. Maybe it
+ doesn't. But a lot of people asked for this feature, so here you go 🤝
+