Merge branch 'main' of https://gitea.cognizata.com/Atapy/sorvor-front into main
This commit is contained in:
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
|
||||
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
FROM node:20-slim AS base
|
||||
ENV PNPM_HOME="/pnpm"
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
RUN corepack enable
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS prod-deps
|
||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
|
||||
FROM base AS build
|
||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||
ARG VUE_APP_API_URL
|
||||
RUN pnpm run build
|
||||
|
||||
FROM base AS app
|
||||
COPY --from=prod-deps /app/node_modules /app/node_modules
|
||||
COPY --from=build /app/dist /app/dist
|
||||
RUN pnpm install -g serve
|
||||
EXPOSE 3000
|
||||
EXPOSE 3001
|
||||
CMD [ "serve", "-s", "dist" ]
|
||||
@@ -1,5 +1,4 @@
|
||||
export const CONFIG = {
|
||||
// api_url: "http://localhost:3000",
|
||||
api_url: "http://178.128.18.156:3000",
|
||||
|
||||
// api_url: "http://178.128.18.156:3000",
|
||||
api_url: process.env.VUE_APP_API_URL || "http://localhost:3000",
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import CheckSurvey from "@/views/CheckSurvey.vue";
|
||||
import QuestionList from "@/views/QuestionList.vue";
|
||||
import RegisterForm from "@/views/RegisterForm.vue";
|
||||
import SearchUser from "@/views/SearchUser.vue";
|
||||
import UploadImage from "@/views/UploadImage.vue";
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
@@ -26,6 +27,10 @@ const routes = [
|
||||
path: "/search",
|
||||
component: SearchUser,
|
||||
},
|
||||
{
|
||||
path: "/upload",
|
||||
component: UploadImage,
|
||||
},
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
@@ -33,4 +38,5 @@ const router = createRouter({
|
||||
routes,
|
||||
});
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
||||
|
||||
8
src/utils/fileUpload.js
Normal file
8
src/utils/fileUpload.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export function createFormData(request, file) {
|
||||
const formData = new FormData();
|
||||
Object.entries(request.formData).forEach(([key, value]) => {
|
||||
formData.append(key, value);
|
||||
});
|
||||
formData.append("file", file, file.name);
|
||||
return formData;
|
||||
}
|
||||
@@ -5,6 +5,12 @@ export const client = createTRPCProxyClient({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: CONFIG.api_url,
|
||||
headers: () => {
|
||||
let token = localStorage.getItem("token");
|
||||
return {
|
||||
Authorization: token ? `Bearer ${token}` : "",
|
||||
};
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
45
src/views/UploadImage.vue
Normal file
45
src/views/UploadImage.vue
Normal file
@@ -0,0 +1,45 @@
|
||||
<template>
|
||||
<div>
|
||||
<input
|
||||
type="file"
|
||||
@change="onFileChanged($event)"
|
||||
accept="image/*"
|
||||
capture
|
||||
/>
|
||||
<button @click="uploadImage()">Upload</button>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { client } from "@/utils/trpc";
|
||||
import { createFormData } from "@/utils/fileUpload";
|
||||
export default {
|
||||
data: () => ({
|
||||
file: null,
|
||||
}),
|
||||
methods: {
|
||||
onFileChanged(event) {
|
||||
const file = event.target.files[0];
|
||||
this.file = file;
|
||||
},
|
||||
|
||||
async uploadImage() {
|
||||
if (!this.file) {
|
||||
return;
|
||||
}
|
||||
let request = await client.user.requestChangeImage.mutate({
|
||||
imageName: this.file.name,
|
||||
contentType: this.file.type,
|
||||
});
|
||||
let formData = createFormData(request, this.file);
|
||||
await fetch(request.postURL, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
}).then(() => {
|
||||
client.user.confirmChangeImage.mutate();
|
||||
});
|
||||
console.log("done");
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style></style>
|
||||
Reference in New Issue
Block a user