Skip to content

Commit

Permalink
Api url (#473)
Browse files Browse the repository at this point in the history
* update
  • Loading branch information
swuecho authored Jun 9, 2024
1 parent edf1f58 commit 2b65cf2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
38 changes: 21 additions & 17 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,53 +141,51 @@ func main() {
// create a new Gorilla Mux router instance
// Create a new router
router := mux.NewRouter()

apiRouter := router.PathPrefix("/api").Subrouter()

sqlc_q := sqlc_queries.New(pgdb)
secretService := NewJWTSecretService(sqlc_q)
jwtSecretAndAud, err = secretService.GetOrCreateJwtSecret(context.Background(), "chat")
if err != nil {
log.Fatal(err)
}
ChatModelHandler := NewChatModelHandler(sqlc_q)
ChatModelHandler.Register(router)
ChatModelHandler.Register(apiRouter)

// create a new AuthUserHandler instance
userHandler := NewAuthUserHandler(sqlc_q)
// register the AuthUserHandler with the router
userHandler.Register(router)
userHandler.Register(apiRouter)

promptHandler := NewChatPromptHandler(sqlc_q)
promptHandler.Register(router)
promptHandler.Register(apiRouter)

chatSessionHandler := NewChatSessionHandler(sqlc_q)
chatSessionHandler.Register(router)
chatSessionHandler.Register(apiRouter)

chatMessageHandler := NewChatMessageHandler(sqlc_q)
chatMessageHandler.Register(router)
chatMessageHandler.Register(apiRouter)

chatSnapshotHandler := NewChatSnapshotHandler(sqlc_q)
chatSnapshotHandler.Register(router)
chatSnapshotHandler.Register(apiRouter)

activeSessionHandler := NewUserActiveChatSessionHandler(sqlc_q)
activeSessionHandler.Register(router)
activeSessionHandler.Register(apiRouter)

// create a new ChatHandler instance
chatHandler := NewChatHandler(sqlc_q)
chatHandler.Register(router)
chatHandler.Register(apiRouter)

user_model_privilege_handler := NewUserChatModelPrivilegeHandler(sqlc_q)
user_model_privilege_handler.Register(router)
user_model_privilege_handler.Register(apiRouter)

chatFileHandler := NewChatFileHandler(sqlc_q)
chatFileHandler.Register(router)
chatFileHandler.Register(apiRouter)

router.HandleFunc("/tts", handleTTSRequest)
apiRouter.HandleFunc("/tts", handleTTSRequest)

router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
tpl, err1 := route.GetPathTemplate()
met, err2 := route.GetMethods()
fmt.Println(tpl, err1, met, err2)
return nil
})


// Embed static/* directory
fs := http.FileServer(http.FS(static.StaticFiles))
Expand Down Expand Up @@ -224,6 +222,12 @@ func main() {
// loggedMux := loggingMiddleware(router, logger)
loggedRouter := handlers.LoggingHandler(logger.Out, router)

router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
tpl, err1 := route.GetPathTemplate()
met, err2 := route.GetMethods()
fmt.Println(tpl, err1, met, err2)
return nil
})
// fly.io

if os.Getenv("FLY_APP_NAME") != "" {
Expand Down
6 changes: 3 additions & 3 deletions api/middleware_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func AdminOnlyHandlerFunc(handlerFunc http.HandlerFunc) http.HandlerFunc {
func IsAuthorizedMiddleware(handler http.Handler) http.Handler {
noAuthPaths := map[string]bool{
"/": true,
"/login": true,
"/signup": true,
"/tts": true,
"/api/login": true,
"/api/signup": true,
"/api/tts": true,
}
jwtSigningKey := []byte(jwtSecretAndAud.Secret)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion web/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VITE_GLOB_API_URL=/
VITE_GLOB_API_URL=/api

4 changes: 2 additions & 2 deletions web/src/views/chat/components/Uploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getChatFilesList } from '@/api/chat_file'
const baseURL = import.meta.env.VITE_GLOB_API_URL
const actionURL = baseURL != "/" ? baseURL + '/upload' : '/upload'
const actionURL = baseURL + '/upload'
const queryClient = useQueryClient()
Expand Down Expand Up @@ -109,7 +109,7 @@ function handleRemove({ file }: { file: UploadFileInfo }) {
}
function fileUrl(file: UploadFileInfo): string {
const file_id = file.url?.split('/').pop();
const file_id = file.url?.split('/').pop();
const url = `/download/${file_id}`
return url
}
Expand Down
18 changes: 7 additions & 11 deletions web/src/views/chat/components/UploaderReadOnly.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<template>
<div>
<NUpload :with-credentials="true" :action="actionURL" :headers="headers" :data="data" :file-list="fileListData"
:show-download-button="true" :show-remove-button="false" :show-cancel-button="false"
@finish="handleFinish" @before-upload="beforeUpload" @remove="handleRemove"
@download="handleDownload" @update:file-list="handleFileListUpdate"
@preview="handlePreview"
>
<NUpload :with-credentials="true" :action="actionURL" :headers="headers" :data="data"
:file-list="fileListData" :show-download-button="true" :show-remove-button="false"
:show-cancel-button="false" @finish="handleFinish" @before-upload="beforeUpload"
@remove="handleRemove" @download="handleDownload" @update:file-list="handleFileListUpdate"
@preview="handlePreview">
</NUpload>
</div>
</template>
Expand All @@ -22,8 +21,7 @@ const queryClient = useQueryClient()
const baseURL = import.meta.env.VITE_GLOB_API_URL
const actionURL = baseURL != "/" ? baseURL + '/upload' : '/upload'
const actionURL = baseURL + '/upload'
interface Props {
sessionUuid: string
Expand All @@ -50,8 +48,6 @@ const fileDeleteMutation = useMutation({
})
// const emit = defineEmits(['update:showUploadModal']);
// login modal will appear when there is no token
Expand Down Expand Up @@ -99,7 +95,7 @@ function handleFinish({ file, event }: { file: UploadFileInfo, event?: ProgressE
}
function fileUrl(file: UploadFileInfo): string {
const file_id = file.url?.split('/').pop();
const file_id = file.url?.split('/').pop();
const url = `/download/${file_id}`
return url
}
Expand Down
1 change: 0 additions & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default defineConfig((env) => {
'/api': {
target: 'http://localhost:8080/',
changeOrigin: true, // 允许跨域
rewrite: path => path.replace('/api/', '/'),
},
},
},
Expand Down

0 comments on commit 2b65cf2

Please sign in to comment.