Compare commits

..

No commits in common. "e01dbd5c3121f944c33af8cccd763f5d61c386b3" and "3626b074bd8762b3c25af6dfc8675254063b7e1c" have entirely different histories.

6 changed files with 16 additions and 197 deletions

View file

@ -167,11 +167,10 @@ Vue.createApp({
this.toggleModal(); this.toggleModal();
}, },
deleteItem() { deleteItem() {
// eslint-disable-next-line no-undef if ( vueType === 'private' ) {
if (vueType !== "private") {
return false; return false;
} }
return axios axios
.delete(`/api/v1/albums/${this.itemId}`) .delete(`/api/v1/albums/${this.itemId}`)
.then(() => { .then(() => {
this.fetch(); this.fetch();
@ -187,11 +186,10 @@ Vue.createApp({
}); });
}, },
shareCollection() { shareCollection() {
// eslint-disable-next-line no-undef if ( vueType === 'private' ) {
if (vueType !== "private") {
return false; return false;
} }
return axios axios
.patch(`/api/v1/me`, { .patch(`/api/v1/me`, {
isPublicCollection: !this.isPublicCollection, isPublicCollection: !this.isPublicCollection,
}) })
@ -221,16 +219,19 @@ Vue.createApp({
}); });
}, },
renderAlbumTitle(item) { renderAlbumTitle(item) {
let render = ""; let render = '';
for (let i = 0; i < item.artists.length; i += 1) { for ( let i = 0 ; i < item.artists.length ; i += 1 ) {
const { name, join } = item.artists[i]; const {
render += `${name} ${join ? `${join} ` : ""}`; name,
join,
} = item.artists[i];
render += `${name} ${join ? `${join} ` : ''}`;
} }
render += `- ${item.title}`; render += `- ${item.title}`;
return render; return render;
}, }
}, },
}).mount("#collection"); }).mount("#collection");

View file

@ -4,8 +4,6 @@ if (typeof item !== "undefined") {
return { return {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
item, item,
// eslint-disable-next-line no-undef
canShareItem,
tracklist: [], tracklist: [],
identifiers: [], identifiers: [],
modalIsVisible: false, modalIsVisible: false,
@ -14,11 +12,6 @@ if (typeof item !== "undefined") {
preview: null, preview: null,
index: null, index: null,
showModalDelete: false, showModalDelete: false,
showModalShare: false,
shareMessage: "",
shareMessageTransformed: "",
shareMessageLength: 0,
shareSubmiting: false,
}; };
}, },
created() { created() {
@ -30,26 +23,6 @@ if (typeof item !== "undefined") {
destroyed() { destroyed() {
window.removeEventListener("keydown", this.changeImage); window.removeEventListener("keydown", this.changeImage);
}, },
watch: {
shareMessage(message) {
const video =
this.item.videos && this.item.videos.length > 0
? this.item.videos[0].uri
: "";
this.shareMessageTransformed = message
.replaceAll("{artist}", this.item.artists[0].name)
.replaceAll("{format}", this.item.formats[0].name)
.replaceAll("{year}", this.item.year)
.replaceAll("{video}", video)
.replaceAll("{album}", this.item.title);
this.shareMessageLength = this.shareMessageTransformed.replace(
video,
new Array(36).join("#")
).length;
},
},
methods: { methods: {
setIdentifiers() { setIdentifiers() {
this.identifiers = []; this.identifiers = [];
@ -216,33 +189,6 @@ if (typeof item !== "undefined") {
goToArtist() { goToArtist() {
return ""; return "";
}, },
shareAlbum() {
if (this.shareSubmiting) {
return false;
}
this.shareSubmiting = true;
axios
.post(`/api/v1/albums/${this.item._id}/share`, {
message: this.shareMessageTransformed,
})
.then(() => {
showToastr("Album partagé", true);
this.shareMessage = "";
this.showModalShare = false;
})
.catch((err) => {
showToastr(
err.response?.data?.message ||
"Impossible de partager cet album",
false
);
})
.finally(() => {
this.shareSubmiting = false;
});
return true;
},
}, },
}).mount("#ma-collection-details"); }).mount("#ma-collection-details");
} }

View file

@ -31,12 +31,13 @@
max-width: 100%; max-width: 100%;
width: 100%; width: 100%;
background-color: var(--input-color); background-color: var(--input-color);
border: 1px solid var(--input-active-color) !important; border: 1px solid transparent !important;
color: var(--input-font-color); color: var(--input-font-color);
@include transition() {} @include transition() {}
&:focus-visible { &:focus-visible {
outline: unset; outline: unset;
border-color: var(--input-active-color) !important;
} }
} }

View file

@ -297,7 +297,7 @@ Publié automatiquement via #musictopus`;
*/ */
async deleteOne() { async deleteOne() {
const res = await AlbumsModel.findOneAndDelete({ const res = await AlbumsModel.findOneAndDelete({
User: this.req.user._id, user: this.req.user._id,
_id: this.req.params.itemId, _id: this.req.params.itemId,
}); });
@ -312,83 +312,6 @@ Publié automatiquement via #musictopus`;
); );
} }
async shareOne() {
const { message: status } = this.req.body;
const { itemId: _id } = this.req.params;
const { _id: User } = this.req.user;
const query = {
_id,
User,
};
const album = await AlbumsModel.findOne(query);
if (!album) {
throw new ErrorEvent(
404,
"Mise à jour",
"Impossible de trouver cet album"
);
}
const { mastodon: mastodonConfig } = this.req.user;
const { publish, token, url } = mastodonConfig;
if (publish && url && token) {
const M = new Mastodon({
access_token: token,
api_url: url,
});
const media_ids = [];
if (album.images.length > 0) {
for (let i = 0; i < album.images.length; i += 1) {
if (media_ids.length === 4) {
break;
}
const filename = `${v4()}.jpg`;
const file = `/tmp/${filename}`;
// eslint-disable-next-line no-await-in-loop
const { data: buff } = await axios.get(
album.images[i].uri,
{
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0",
},
responseType: "arraybuffer",
}
);
fs.writeFileSync(file, buff);
// eslint-disable-next-line no-await-in-loop
const { data: media } = await M.post("media", {
file: fs.createReadStream(file),
});
const { id } = media;
media_ids.push(id);
fs.unlinkSync(file);
}
}
await M.post("statuses", { status, media_ids });
} else {
throw new ErrorEvent(
406,
`Vous n'avez pas configuré vos options de partage sur votre compte`
);
}
return true;
}
/** /**
* Méthode permettant de créer la page "ma-collection" * Méthode permettant de créer la page "ma-collection"
*/ */

View file

@ -68,17 +68,4 @@ router
} }
}); });
router
.route("/:itemId/share")
.post(ensureLoggedIn("/connexion"), async (req, res, next) => {
try {
const albums = new Albums(req);
const data = await albums.shareOne();
sendResponse(req, res, data);
} catch (err) {
next(err);
}
});
export default router; export default router;

View file

@ -8,7 +8,6 @@
- {{item.title}} - {{item.title}}
<i class="icon-trash" title="Supprimer cette fiche" @click="showConfirmDelete()"></i> <i class="icon-trash" title="Supprimer cette fiche" @click="showConfirmDelete()"></i>
<i class="icon-refresh" title="Mettre à jour les données de cette fiche" @click="updateItem()"></i> <i class="icon-refresh" title="Mettre à jour les données de cette fiche" @click="updateItem()"></i>
<i class="icon-share" title="Partager cet album sur le fédiverse" @click="showModalShare = true" v-if="canShareItem"></i>
</h1> </h1>
<div class="grid sm:grid-cols-3 gap-16"> <div class="grid sm:grid-cols-3 gap-16">
<div class="text-center"> <div class="text-center">
@ -183,46 +182,8 @@
</footer> </footer>
</div> </div>
</div> </div>
<div class="modal" :class="{'is-visible': showModalShare}">
<div class="modal-background"></div>
<div class="modal-card">
<header>Partager un album sur le fédiverse</header>
<section>
<div class="grid grid-cols-1 md:grid-cols-2 gap-10">
<div class="field">
<label for="shareMessage">Message</label>
<textarea
name="shareMessage"
id="shareMessage"
v-model="shareMessage"
rows="6"
></textarea>
Caractères utilisés : {{ shareMessageLength }}
</div>
<div>
<small>
Variables possibles :
<ul>
<li>{artist}, exemple : Iron Maiden</li>
<li>{album}, exemple : Powerslave</li>
<li>{format}, exemple : Cassette</li>
<li>{year}, exemple: 1984</li>
<li>{video}, exemple : https://www.youtube.com/watch?v=Qx0s8OqgBIw</li>
</ul>
</small>
</div>
</div>
</section>
<footer>
<button :class="['button is-primary', shareSubmiting ? 'is-disabled' : '']" @click="shareAlbum">Partager</button>
<button class="button" @click="showModalShare=!showModalShare">Annuler</button>
</footer>
</div>
</div>
</main> </main>
<script> <script>
const item = <%- JSON.stringify(page.item) %>; const item = <%- JSON.stringify(page.item) %>;
const canShareItem = <%= user.mastodon?.publish || false %>;
</script> </script>