Skip to content

Commit

Permalink
fix: add sqlite wal mode && fix thumbnail ffmpeg && fix context group
Browse files Browse the repository at this point in the history
  • Loading branch information
itzngga committed Dec 7, 2023
1 parent a7cad20 commit aa097e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 6 additions & 0 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func NewContainer(options *options.Options) (*Container, error) {
if err != nil {
return nil, fmt.Errorf("failed to open database: %w", err)
}

_, err = db.Exec("PRAGMA journal_mode=WAL")
if err != nil {
return nil, fmt.Errorf("error sqlite: %w", err)
}

sqlite := sqlstore.NewWithDB(db, "sqlite3", waLog.Stdout("Database", "ERROR", true))
err = sqlite.Upgrade()
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions context/context_group_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ func (context *Ctx) RemoveMemberFromGroup(jids []waTypes.JID) error {
return err
}

changes := map[waTypes.JID]whatsmeow.ParticipantChange{}
changes := make([]waTypes.JID, 0)
for _, jid := range jids {
changes[jid] = whatsmeow.ParticipantChangeRemove
changes = append(changes, jid)
}

_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes)
_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes, whatsmeow.ParticipantChangeRemove)
return err
}

Expand All @@ -29,12 +29,12 @@ func (context *Ctx) AddMemberToGroup(jids []waTypes.JID) error {
return err
}

changes := map[waTypes.JID]whatsmeow.ParticipantChange{}
changes := make([]waTypes.JID, 0)
for _, jid := range jids {
changes[jid] = whatsmeow.ParticipantChangeAdd
changes = append(changes, jid)
}

_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes)
_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes, whatsmeow.ParticipantChangeAdd)
return err
}

Expand All @@ -44,12 +44,12 @@ func (context *Ctx) PromoteMemberInGroup(jids []waTypes.JID) error {
return err
}

changes := map[waTypes.JID]whatsmeow.ParticipantChange{}
changes := make([]waTypes.JID, 0)
for _, jid := range jids {
changes[jid] = whatsmeow.ParticipantChangePromote
changes = append(changes, jid)
}

_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes)
_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes, whatsmeow.ParticipantChangePromote)
return err
}

Expand All @@ -59,12 +59,12 @@ func (context *Ctx) DemoteMemberInGroup(jids []waTypes.JID) error {
return err
}

changes := map[waTypes.JID]whatsmeow.ParticipantChange{}
changes := make([]waTypes.JID, 0)
for _, jid := range jids {
changes[jid] = whatsmeow.ParticipantChangeDemote
changes = append(changes, jid)
}

_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes)
_, err := context.Client().UpdateGroupParticipants(context.ChatJID(), changes, whatsmeow.ParticipantChangeDemote)
return err
}

Expand Down
10 changes: 6 additions & 4 deletions util/thumbnail/thumbnail.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func CreateImageThumbnail(data []byte) []byte {
return nil
}

reader = nil
writer = nil
return writer.Bytes()
}

Expand All @@ -32,11 +34,9 @@ func CreateVideoThumbnail(data []byte) []byte {
err := cmdchain.Builder().
Join("ffmpeg", "-y", "-hide_banner", "-loglevel", "panic",
"-f", "mp4", "-i", "pipe:0",
"-ss", "00:00:00", "-t", "00:00:01",
"-vf", "'select=gt(scene\\,0.4)'",
"-frames:v", "5",
"-filter_complex", "'scale=72:72,select=between(t\\,10\\,20)*eq(pict_type\\,I)'",
"-update", "true",
"-fps_mode", "vfr",
"-vf", "scale=72:72",
"-f", "image2pipe",
"pipe:1").
WithInjections(reader).Finalize().
Expand All @@ -45,5 +45,7 @@ func CreateVideoThumbnail(data []byte) []byte {
return nil
}

reader = nil
writer = nil
return writer.Bytes()
}

0 comments on commit aa097e5

Please sign in to comment.