modified: begushiybashkir/bbvue/src/components/AvatarUpload.vue
modified: begushiybashkir/bbvue/src/stores/auth.js modified: serv_nginx/api_bb/.env modified: serv_nginx/api_bb/internal/config/config.go modified: serv_nginx/api_bb/internal/models/user.go modified: serv_nginx/api_bb/internal/routes/routes.go modified: serv_nginx/nginx/nginx-ssl.conf some for get photo from api_bb
This commit is contained in:
@@ -12,13 +12,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/gif"
|
||||
@change="handleFileSelect"
|
||||
style="display: none;"
|
||||
>
|
||||
<input ref="fileInput" type="file" accept="image/jpeg,image/png,image/gif" @change="handleFileSelect"
|
||||
style="display: none;">
|
||||
|
||||
<div v-if="uploading" class="upload-progress">
|
||||
Загрузка...
|
||||
@@ -63,9 +58,14 @@ export default {
|
||||
user: {
|
||||
immediate: true,
|
||||
handler(newUser) {
|
||||
console.log('User data:', newUser)
|
||||
if (newUser?.avatar) {
|
||||
this.previewUrl = this.getFullAvatarUrl(newUser.avatar)
|
||||
console.log('Avatar path:', newUser.avatar)
|
||||
const fullUrl = this.getFullAvatarUrl(newUser.avatar)
|
||||
console.log('Full avatar URL:', fullUrl)
|
||||
this.previewUrl = fullUrl
|
||||
} else {
|
||||
console.log('No avatar found')
|
||||
this.previewUrl = null
|
||||
}
|
||||
}
|
||||
@@ -74,8 +74,22 @@ export default {
|
||||
methods: {
|
||||
getFullAvatarUrl(avatarPath) {
|
||||
if (!avatarPath) return null
|
||||
|
||||
// Если путь уже полный URL
|
||||
if (avatarPath.startsWith('http')) return avatarPath
|
||||
|
||||
// Если путь начинается с /uploads
|
||||
if (avatarPath.startsWith('/uploads/')) {
|
||||
return `${import.meta.env.VITE_API_BASE_URL}${avatarPath}`
|
||||
}
|
||||
|
||||
// Если путь относительный (avatars/filename.jpg)
|
||||
if (avatarPath.startsWith('avatars/')) {
|
||||
return `${import.meta.env.VITE_API_BASE_URL}/uploads/${avatarPath}`
|
||||
}
|
||||
|
||||
// По умолчанию
|
||||
return `${import.meta.env.VITE_API_BASE_URL}/uploads/${avatarPath}`
|
||||
},
|
||||
|
||||
triggerFileInput() {
|
||||
|
||||
@@ -130,9 +130,9 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
const result = handleApiError(error)
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const deleteAvatar = async () => {
|
||||
const deleteAvatar = async () => {
|
||||
try {
|
||||
const response = await apiClient.delete('/user/avatar/deleteg')
|
||||
|
||||
@@ -147,7 +147,7 @@ const deleteAvatar = async () => {
|
||||
const result = handleApiError(error)
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
|
||||
@@ -13,3 +13,4 @@ ENVIRONMENT=development
|
||||
|
||||
# app
|
||||
REST_API_VERSION=1.0.0
|
||||
VITE_API_BASE_URL=https://begushiybashkir.ru
|
||||
@@ -12,6 +12,7 @@ type Config struct {
|
||||
Port string
|
||||
DatabaseURL string
|
||||
JWTSecret string
|
||||
StaticURL string `env:"STATIC_URL" envDefault:"http://localhost:8080"`
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
|
||||
@@ -30,7 +30,7 @@ type UserUpdate struct {
|
||||
ID uint `json:"id"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
Avatar string `json:"avatar"` // Добавить поле аватара
|
||||
Avatar string `json:"avatar"`
|
||||
Phone string `json:"phone"`
|
||||
Experience string `json:"experience"`
|
||||
Goals string `json:"goals"`
|
||||
|
||||
@@ -23,6 +23,10 @@ func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
|
||||
r.Use(m)
|
||||
}
|
||||
|
||||
// Serve static files (avatars) - ДОБАВЬТЕ ЭТО
|
||||
r.Handle("/uploads/*", http.StripPrefix("/uploads/",
|
||||
http.FileServer(http.Dir("/app/uploads"))))
|
||||
|
||||
// Initialize repositories
|
||||
userRepo := repository.NewUserRepository(db)
|
||||
newsRepo := repository.NewNewsRepository(db)
|
||||
|
||||
@@ -134,4 +134,11 @@ server {
|
||||
proxy_read_timeout 600;
|
||||
}
|
||||
|
||||
|
||||
location /uploads/ {
|
||||
alias /app/uploads/;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user