🗑️ Remove firebase deps
This commit is contained in:
parent
c7ba566c48
commit
61eff6ea49
@ -1,13 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/i18n"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/external"
|
"git.solsynth.dev/hydrogen/passport/pkg"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/i18n"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/grpc"
|
"git.solsynth.dev/hydrogen/passport/pkg/grpc"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/server"
|
"git.solsynth.dev/hydrogen/passport/pkg/server"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/services"
|
"git.solsynth.dev/hydrogen/passport/pkg/services"
|
||||||
@ -45,14 +45,6 @@ func main() {
|
|||||||
log.Fatal().Err(err).Msg("An error occurred when running database auto migration.")
|
log.Fatal().Err(err).Msg("An error occurred when running database auto migration.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// External
|
|
||||||
// All the things are optional so when error occurred the server won't crash
|
|
||||||
if err := external.SetupFirebase(viper.GetString("external.firebase.credentials")); err != nil {
|
|
||||||
log.Error().Err(err).Msg("An error occurred when starting firebase communicating...")
|
|
||||||
} else {
|
|
||||||
log.Info().Msg("Successfully setup firebase communication.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect other services
|
// Connect other services
|
||||||
if err := grpc.ConnectPaperclip(); err != nil {
|
if err := grpc.ConnectPaperclip(); err != nil {
|
||||||
log.Fatal().Err(err).Msg("An error occurred when connecting to paperclip...")
|
log.Fatal().Err(err).Msg("An error occurred when connecting to paperclip...")
|
||||||
|
@ -12,6 +12,7 @@ var AutoMaintainRange = []any{
|
|||||||
&models.AccountPage{},
|
&models.AccountPage{},
|
||||||
&models.AccountContact{},
|
&models.AccountContact{},
|
||||||
&models.AccountFriendship{},
|
&models.AccountFriendship{},
|
||||||
|
&models.Badge{},
|
||||||
&models.Realm{},
|
&models.Realm{},
|
||||||
&models.RealmMember{},
|
&models.RealmMember{},
|
||||||
&models.AuthTicket{},
|
&models.AuthTicket{},
|
||||||
|
21
pkg/external/firebase.go
vendored
21
pkg/external/firebase.go
vendored
@ -1,21 +0,0 @@
|
|||||||
package external
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
firebase "firebase.google.com/go"
|
|
||||||
"google.golang.org/api/option"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Fire *firebase.App
|
|
||||||
|
|
||||||
func SetupFirebase(credentials string) error {
|
|
||||||
opt := option.WithCredentialsFile(credentials)
|
|
||||||
app, err := firebase.NewApp(context.Background(), nil, opt)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
Fire = app
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -22,6 +22,7 @@ type Account struct {
|
|||||||
|
|
||||||
Profile AccountProfile `json:"profile"`
|
Profile AccountProfile `json:"profile"`
|
||||||
PersonalPage AccountPage `json:"personal_page"`
|
PersonalPage AccountPage `json:"personal_page"`
|
||||||
|
Badges []Badge `json:"badges"`
|
||||||
Contacts []AccountContact `json:"contacts"`
|
Contacts []AccountContact `json:"contacts"`
|
||||||
RealmIdentities []RealmMember `json:"realm_identities"`
|
RealmIdentities []RealmMember `json:"realm_identities"`
|
||||||
|
|
||||||
|
10
pkg/models/badges.go
Normal file
10
pkg/models/badges.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Badge struct {
|
||||||
|
BaseModel
|
||||||
|
|
||||||
|
Type string `json:"type"`
|
||||||
|
Label string `json:"label"`
|
||||||
|
Color string `json:"color"`
|
||||||
|
AccountID uint `json:"account_id"`
|
||||||
|
}
|
@ -1,15 +1,18 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/datatypes"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/datatypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
|
|
||||||
|
Type string `json:"type"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
Metadata datatypes.JSONMap `json:"metadata"`
|
||||||
Links datatypes.JSONSlice[NotificationLink] `json:"links"`
|
Links datatypes.JSONSlice[NotificationLink] `json:"links"`
|
||||||
IsImportant bool `json:"is_important"`
|
IsImportant bool `json:"is_important"`
|
||||||
IsRealtime bool `json:"is_realtime" gorm:"-"`
|
IsRealtime bool `json:"is_realtime" gorm:"-"`
|
||||||
@ -25,7 +28,7 @@ type NotificationLink struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NotifySubscriberFirebase = "firebase"
|
NotifySubscriberAPN = "apple"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NotificationSubscriber struct {
|
type NotificationSubscriber struct {
|
||||||
|
@ -23,6 +23,7 @@ func getUserinfo(c *fiber.Ctx) error {
|
|||||||
Where(&models.Account{BaseModel: models.BaseModel{ID: user.ID}}).
|
Where(&models.Account{BaseModel: models.BaseModel{ID: user.ID}}).
|
||||||
Preload("Profile").
|
Preload("Profile").
|
||||||
Preload("Contacts").
|
Preload("Contacts").
|
||||||
|
Preload("Badges").
|
||||||
First(&data).Error; err != nil {
|
First(&data).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ func getOtherUserinfo(c *fiber.Ctx) error {
|
|||||||
Where(&models.Account{Name: alias}).
|
Where(&models.Account{Name: alias}).
|
||||||
Omit("tickets", "challenges", "factors", "events", "clients", "notifications", "notify_subscribers").
|
Omit("tickets", "challenges", "factors", "events", "clients", "notifications", "notify_subscribers").
|
||||||
Preload("Profile").
|
Preload("Profile").
|
||||||
|
Preload("Badges").
|
||||||
First(&account).Error; err != nil {
|
First(&account).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"firebase.google.com/go/messaging"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/database"
|
"git.solsynth.dev/hydrogen/passport/pkg/database"
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/external"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/models"
|
"git.solsynth.dev/hydrogen/passport/pkg/models"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
@ -73,35 +70,7 @@ func PushNotification(notification models.Notification) error {
|
|||||||
|
|
||||||
for _, subscriber := range subscribers {
|
for _, subscriber := range subscribers {
|
||||||
switch subscriber.Provider {
|
switch subscriber.Provider {
|
||||||
case models.NotifySubscriberFirebase:
|
case models.NotifySubscriberAPN:
|
||||||
if external.Fire == nil {
|
|
||||||
// Didn't configure for firebase support
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
client, err := external.Fire.Messaging(ctx)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn().Err(err).Msg("An error occurred when getting firebase FCM client...")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
message := &messaging.Message{
|
|
||||||
Notification: &messaging.Notification{
|
|
||||||
Title: notification.Subject,
|
|
||||||
Body: notification.Content,
|
|
||||||
},
|
|
||||||
Token: subscriber.DeviceToken,
|
|
||||||
}
|
|
||||||
|
|
||||||
if response, err := client.Send(ctx, message); err != nil {
|
|
||||||
log.Warn().Err(err).Msg("An error occurred when notify subscriber though firebase FCM...")
|
|
||||||
} else {
|
|
||||||
log.Debug().
|
|
||||||
Str("response", response).
|
|
||||||
Int("subscriber", int(subscriber.ID)).
|
|
||||||
Msg("Notified to subscriber though firebase FCM.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,6 @@ print_routes = false
|
|||||||
endpoint = "http://localhost:8443"
|
endpoint = "http://localhost:8443"
|
||||||
grpc_endpoint = "localhost:7443"
|
grpc_endpoint = "localhost:7443"
|
||||||
|
|
||||||
[external.firebase]
|
|
||||||
credentials = "dist/firebase-certs.json"
|
|
||||||
|
|
||||||
[mailer]
|
[mailer]
|
||||||
name = "Alphabot <alphabot@smartsheep.studio>"
|
name = "Alphabot <alphabot@smartsheep.studio>"
|
||||||
smtp_host = "smtp.exmail.qq.com"
|
smtp_host = "smtp.exmail.qq.com"
|
||||||
|
Loading…
Reference in New Issue
Block a user