kopia lustrzana https://codeberg.org/nmkj/audon
fix avatar filename
rodzic
a91d7d340a
commit
f9c35e0170
|
@ -3365,6 +3365,20 @@
|
|||
"rxjs": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "4.9.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz",
|
||||
"integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ua-parser-js": {
|
||||
"version": "1.0.32",
|
||||
"resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.32.tgz",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { defineStore } from "pinia";
|
||||
import axios from "axios";
|
||||
import { login } from "masto";
|
||||
import { createClient } from "masto";
|
||||
import { webfinger } from "../assets/utils";
|
||||
|
||||
export const useMastodonStore = defineStore("mastodon", {
|
||||
|
@ -28,7 +28,7 @@ export const useMastodonStore = defineStore("mastodon", {
|
|||
async fetchToken() {
|
||||
const resp = await axios.get("/api/token");
|
||||
this.oauth = resp.data;
|
||||
const client = await login({
|
||||
const client = createClient({
|
||||
url: this.oauth.url,
|
||||
accessToken: this.oauth.token,
|
||||
disableVersionCheck: true,
|
||||
|
@ -40,22 +40,24 @@ export const useMastodonStore = defineStore("mastodon", {
|
|||
},
|
||||
async updateAvatar(img) {
|
||||
if (this.client === null) return;
|
||||
const avatar = await (await fetch(img)).blob();
|
||||
const avatarBlob = await (await fetch(img)).blob();
|
||||
this.userinfo = await this.client.v1.accounts.updateCredentials({
|
||||
avatar,
|
||||
avatar: new File([avatarBlob], `${Date.now()}.gif`),
|
||||
});
|
||||
},
|
||||
async revertAvatar() {
|
||||
const t = setTimeout(async () => {
|
||||
const oldAvatar = sessionStorage.getItem("avatar_old");
|
||||
sessionStorage.removeItem("avatar_old");
|
||||
const token = await axios.get("/api/token");
|
||||
const oldAvatar = sessionStorage.getItem("avatar_old_data");
|
||||
sessionStorage.removeItem("avatar_old_data");
|
||||
sessionStorage.removeItem("avatar_timeout");
|
||||
if (this.client === null || !oldAvatar) return;
|
||||
if (this.client === null || !oldAvatar || !token.data.audon.avatar)
|
||||
return;
|
||||
const resp = await axios.delete("/api/room");
|
||||
if (resp.status === 200) {
|
||||
const avatar = await (await fetch(oldAvatar)).blob();
|
||||
const avatarBlob = await (await fetch(oldAvatar)).blob();
|
||||
this.userinfo = await this.client.v1.accounts.updateCredentials({
|
||||
avatar,
|
||||
avatar: new File([avatarBlob], token.data.audon.avatar),
|
||||
});
|
||||
}
|
||||
}, 2 * 1000);
|
||||
|
|
|
@ -28,7 +28,7 @@ import {
|
|||
DataPacket_Kind,
|
||||
AudioPresets,
|
||||
} from "livekit-client";
|
||||
import { login } from "masto";
|
||||
import { createClient } from "masto";
|
||||
import { useVuelidate } from "@vuelidate/core";
|
||||
import { helpers, maxLength, required } from "@vuelidate/validators";
|
||||
import NoSleep from "@uriopass/nosleep.js";
|
||||
|
@ -267,7 +267,8 @@ export default {
|
|||
clearTimeout(timeoutID);
|
||||
sessionStorage.removeItem("avatar_timeout");
|
||||
}
|
||||
await this.donStore.fetchToken();
|
||||
const token = await axios.get("/api/token");
|
||||
this.donStore.oauth = token.data;
|
||||
let avatarURL = this.donStore.userinfo.avatar;
|
||||
if (this.donStore.oauth.audon?.avatar) {
|
||||
avatarURL = "";
|
||||
|
@ -275,7 +276,7 @@ export default {
|
|||
const resp = await axios.postForm(`/api/room/${this.roomID}`, {
|
||||
avatar: avatarURL,
|
||||
});
|
||||
sessionStorage.setItem("avatar_old", resp.data.original);
|
||||
sessionStorage.setItem("avatar_old_data", resp.data.original);
|
||||
if (resp.data.indicator && !timeout) {
|
||||
try {
|
||||
await this.donStore.updateAvatar(resp.data.indicator);
|
||||
|
@ -615,7 +616,7 @@ export default {
|
|||
if (this.cachedMastoData[identity] !== undefined) return;
|
||||
try {
|
||||
const url = new URL(remote_url);
|
||||
const mastoClient = await login({
|
||||
const mastoClient = createClient({
|
||||
url: url.origin,
|
||||
disableVersionCheck: true,
|
||||
});
|
||||
|
|
2
user.go
2
user.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
|
@ -40,6 +41,7 @@ func (a *AudonUser) InLivekit(ctx context.Context) (bool, error) {
|
|||
}
|
||||
|
||||
func (a *AudonUser) ClearUserAvatar(ctx context.Context) error {
|
||||
os.Remove(a.getAvatarImagePath(a.AvatarFile))
|
||||
coll := mainDB.Collection(COLLECTION_USER)
|
||||
_, err := coll.UpdateOne(ctx,
|
||||
bson.D{{Key: "audon_id", Value: a.AudonID}},
|
||||
|
|
|
@ -69,9 +69,9 @@ func livekitWebhookHandler(c echo.Context) error {
|
|||
|
||||
<-countdown.C
|
||||
webhookTimerCache.Delete(audonID)
|
||||
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
// defer cancel()
|
||||
ctx := context.TODO()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
// ctx := context.TODO()
|
||||
|
||||
stillAgain, err := user.InLivekit(ctx)
|
||||
if stillAgain || err != nil {
|
||||
|
@ -87,7 +87,7 @@ func livekitWebhookHandler(c echo.Context) error {
|
|||
avatar := user.getAvatarImagePath(user.AvatarFile)
|
||||
_, err = updateAvatar(ctx, mastoClient, avatar)
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
c.Logger().Warn(err)
|
||||
}
|
||||
user.ClearUserAvatar(ctx)
|
||||
os.Remove(avatar)
|
||||
|
|
Ładowanie…
Reference in New Issue