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