🚸 Prevent re-auth when scope changed

This commit is contained in:
OpenWaygate committed 2024-03-13 10:17:25 +08:00
1 parent af4d7f68ae
commit 110c852301
4 files changed
+6 -14

No files matched your search

+2 -1
View File
@@ -45,8 +45,9 @@ For more information about the client_secrets.json file format, please visit:
https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
`
func NewY2BService(scope string) *youtube.Service {
func NewY2BService() *youtube.Service {
ctx := context.Background()
scope := youtube.YoutubeScope
client := getClient(ctx, scope)
service, err := youtube.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
+4 -6
View File
@@ -11,8 +11,10 @@ import (
)
var (
errGetChannel error = errors.New("failed to get channel")
errUpdateChannel error = errors.New("failed to update channel")
service *youtube.Service = auth.NewY2BService()
part []string = []string{"snippet", "statistics"}
errGetChannel error = errors.New("failed to get channel")
errUpdateChannel error = errors.New("failed to update channel")
)
type Channel struct {
@@ -22,8 +24,6 @@ type Channel struct {
user string
}
var part = []string{"snippet", "statistics"}
type ChannelService interface {
List()
Update()
@@ -66,7 +66,6 @@ func (c *Channel) Update() {
channel.Snippet.Description = c.desc
}
service := auth.NewY2BService(youtube.YoutubeScope)
call := service.Channels.Update(part, channel)
_, err := call.Do()
if err != nil {
@@ -77,7 +76,6 @@ func (c *Channel) Update() {
}
func (c *Channel) get() []*youtube.Channel {
service := auth.NewY2BService(youtube.YoutubeReadonlyScope)
call := service.Channels.List(part)
switch {
case c.id != "":
-3
View File
@@ -6,7 +6,6 @@ import (
"log"
"strings"
"github.com/eat-pray-ai/yutu/pkg/auth"
"google.golang.org/api/youtube/v3"
)
@@ -68,7 +67,6 @@ func (p *Playlist) Insert() {
},
}
service := auth.NewY2BService(youtube.YoutubeScope)
call := service.Playlists.Insert([]string{"snippet", "status"}, upload)
playlist, err := call.Do()
if err != nil {
@@ -79,7 +77,6 @@ func (p *Playlist) Insert() {
}
func (p *Playlist) get(parts []string) []*youtube.Playlist {
service := auth.NewY2BService(youtube.YoutubeReadonlyScope)
call := service.Playlists.List(parts)
switch {
case p.id != "":
-4
View File
@@ -7,7 +7,6 @@ import (
"os"
"strings"
"github.com/eat-pray-ai/yutu/pkg/auth"
"google.golang.org/api/youtube/v3"
)
@@ -57,7 +56,6 @@ func NewVideo(opts ...VideoOption) *Video {
}
func (v *Video) get(parts []string) []*youtube.Video {
service := auth.NewY2BService(youtube.YoutubeReadonlyScope)
call := service.Videos.List(parts)
if v.id != "" {
call = call.Id(v.id)
@@ -118,7 +116,6 @@ func (v *Video) Insert() {
},
}
service := auth.NewY2BService(youtube.YoutubeUploadScope)
call := service.Videos.Insert([]string{"agegating,snippet,status"}, upload)
video, err := call.Media(file).Do()
@@ -156,7 +153,6 @@ func (v *Video) Update() {
}
video.Status.Embeddable = v.embeddable
service := auth.NewY2BService(youtube.YoutubeScope)
call := service.Videos.Update([]string{"snippet,status"}, video)
_, err := call.Do()
if err != nil {