Skip to content

Commit

Permalink
series update, image filename url safe
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRoehm committed Apr 6, 2024
1 parent 117d5f0 commit 8e1ad55
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 21 deletions.
15 changes: 15 additions & 0 deletions assets/css/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,19 @@
.progressbar::-moz-range-progress {
height: 4px;
background: rgb(216, 216, 216);
}

.page-enter-active,
.page-enter-leave {
transition: all 0.5s;
}

.page-enter-from {
opacity: 0;
transform: translateY(100%) scale(0.9);
}

.page-leave-to {
opacity: 0;
transform: translateY(-100%) scale(0.9);
}
22 changes: 22 additions & 0 deletions backend/src/controller/Serie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Serie from "../entities/Serie";
import { setLastAndFirst } from "../services/serieService";
import { simpleSave } from "./All";
import {Request, Response} from "express";
import { respond } from "../tools/Controller";

export async function updateSerieAfterEpisodeChange(request: Request, response: Response) {
try {
const body = request.body as any;
if (body.hasOwnProperty('id')) {
if (body.hasOwnProperty('title')) {
simpleSave<Serie>(Serie, request, response)
} else {
var slug = await setLastAndFirst(body.id)
respond(response,200,slug)
}
} else
return respond(response, 501, "nd data");
} catch (err) {
return respond(response, 500, err.message);
}
}
6 changes: 6 additions & 0 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getRouteSlug } from "./tools/Configuration";
import { getMetadata } from "./controller/Settings";
import { generateRssAction } from "./controller/Podcast";
import { migrateEpisode } from "./controller/Migrate";
import { updateSerieAfterEpisodeChange } from "./controller/Serie";

/**
* All application routes.
Expand Down Expand Up @@ -76,6 +77,11 @@ export const AuthRoutes = [
path: getRouteSlug("SERIES_AP"),
method: "post",
action: (req, res) => simpleSaveMultiple<Serie>(Serie,req,res)
},
{
path: getRouteSlug("SERIE_AP"),
method: "post",
action: (req, res) => updateSerieAfterEpisodeChange(req,res)
},
{
path: getRouteSlug("FETCHLOCAL_AP"),
Expand Down
15 changes: 11 additions & 4 deletions base/Converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,23 @@ export function dateToString(date: Date, locale: string) : string {
return dateToIsoString(date)
}

export function urlFriendlyString(text: string) :string {
return saveSlugFormText(text)
}

export function saveSlugFormText(text: string, lowercase = true): string {
var slug = (lowercase?text.toLowerCase():text);
return slug
.replace(/([:;\.,]+\s?)+/g, "_")
.replace(/([!'/()*"~#@?%&\\:;,<>\*\+\|]|\DE\/EN)+/g, "")
.replace(" deen", "")
.replace("ä", "ae")
.replace("ö", "oe")
.replace("ü", "ue")
.replace("ß", "ss")
.replaceAll("ä", "ae")
.replaceAll("ö", "oe")
.replaceAll("ü", "ue")
.replaceAll("Ä", "Ae")
.replaceAll("Ö", "Oe")
.replaceAll("Ü", "Ue")
.replaceAll("ß", "ss")
.replace(/\s+/g, "_");
}

Expand Down
1 change: 1 addition & 0 deletions components/AudioFileSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default defineComponent({
audioFile.value.imgblob = array2blob(
id3tag.image.data,
id3tag.image.mime)
console.log(audioFile.value.cover_preview)
}
} catch(err) {
console.log(err)
Expand Down
12 changes: 10 additions & 2 deletions components/ImageSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineComponent({
const preview = computed(() => {
if (imgMetadata.value && imgMetadata.value.preview)
return imgMetadata.value.preview;
return imgMetadata.value.preview // (ContentFile.isQualifiedUrl(imgMetadata.value.preview)?:imgMetadata.value.preview);
return "";
})
Expand All @@ -68,7 +68,15 @@ export default defineComponent({
imgMetadata.value.imgWidth = img.naturalWidth;
imgMetadata.value.imgHeight = img.naturalHeight;
callback();
};
}
img.onerror = () => {
imgMetadata.value.preview = undefined;
imgMetadata.value.selectedFile = undefined;
imgMetadata.value.blob = undefined;
imgMetadata.value.imgWidth = 0;
imgMetadata.value.imgHeight = 0;
callback();
}
img.src = source;
}
Expand Down
17 changes: 10 additions & 7 deletions components/PodcastDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import type IPostdata from "~~/base/types/IPostdata";
import validation from "~~/base/PodcastDetailValidation";
import ImageMetadata from "~~/base/types/ImageMetadata";
import type IValidationError from "~~/base/types/IValidationError";
import { saveSlugFormText } from "~~/base/Converters";
import { getSaveFilename, saveSlugFormText } from "~~/base/Converters";
export default defineComponent({
props: {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default defineComponent({
watch(() => fields.value.title, () => generateSlug())
function getImageInFormData() {
function getImageInFormData(newFilename: string) {
const fd = new FormData();
if (imgMetadata.value.selectedFile) {
fd.append("path", SERVER_IMG_PATH + fields.value.slug);
Expand All @@ -121,7 +121,7 @@ export default defineComponent({
imgMetadata.value.selectedFile,
imgMetadata.value.selectedFile.name
);
fd.append("filename", imgMetadata.value.selectedFile.name);
fd.append("filename", newFilename);
}
return fd;
}
Expand All @@ -138,14 +138,17 @@ export default defineComponent({
event.stopImmediatePropagation();
const myFetch = useFetchApi()
var newFilename = ""
if (imgMetadata.value.selectedFile) {
newFilename = getSaveFilename(imgMetadata.value.selectedFile.name)
fields.value.cover_file =
SERVER_IMG_PATH +
fields.value.slug +
"/" +
imgMetadata.value.selectedFile.name
"/" + newFilename
}
errors.value = validation(
fields.value,
imgMetadata.value.imgWidth,
Expand All @@ -165,7 +168,7 @@ export default defineComponent({
var postResult: any = { statusCode: 201 }
try {
if (imgMetadata.value.selectedFile) {
postData.body = getImageInFormData()
postData.body = getImageInFormData(newFilename)
postResult = await myFetch( UPLOAD_AP, postData)
}
} catch (err) {
Expand Down
7 changes: 4 additions & 3 deletions components/SerieDetail.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<PageFormDetail type="serie" :fields="fields" @frmsave="save" @frmremove="remove" @frmcancel="cancel">
<ImageSelector filename="fields.cover_file" :preview="imgMetadata.preview" @imageSelected="imageSelected" />
<ImageSelector :filename="fields.cover_file" :preview="imgMetadata.preview" @imageSelected="imageSelected" />
<!-- Fields-->
<InputArea :name="'title'" :label="'serie.label.title'" :errors="errors" v-model:value="fields.title" />
<InputArea :name="'subtitle'" :label="'serie.label.subtitle'" :errors="errors" v-model:value="fields.subtitle" />
Expand Down Expand Up @@ -30,6 +30,7 @@ import type ISerie from "../base/types/ISerie";
import ImageMetadata from "~~/base/types/ImageMetadata";
import type IValidationError from "~~/base/types/IValidationError";
import { COUNT_AP, SERIES_AP, SERIES_IMG_PATH, SERVER_IMG_PATH, UPLOAD_AP } from "~~/base/Constants";
import { getSaveFilename } from "~/backend/src/tools/Converters";
export default defineComponent({
props: {
Expand Down Expand Up @@ -68,7 +69,7 @@ export default defineComponent({
const fd = new FormData();
if (fileObj) {
fd.append("cover", fileObj, fileObj.name);
fd.append("filename", fileObj.name);
fd.append("filename", getSaveFilename(fileObj.name));
fd.append("path", path)
}
return fd;
Expand All @@ -87,7 +88,7 @@ export default defineComponent({
result = await myFetch( UPLOAD_AP, postData) as any;
}
if ((result as any).statusCode == 201 && fileObj) {
linkToContent = path + "/" + fileObj.name;
linkToContent = path + "/" + getSaveFilename(fileObj.name);
}
return {
link: linkToContent,
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/serie-edit.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('', () => {
beforeEach('Edit serie Page', () => {
cy.login().then( ()=> {
cy.createSerie(slug).then( ser => {
cy.visitNuxtDev('/admin/serie/'+ser.slug)
cy.visitNuxtDev('/admin/serie/'+slug)
})
})
cy.contains('Serie bearbeiten')
Expand Down
8 changes: 8 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export default defineNuxtConfig({
classSuffix: '',
classPrefix: '',
},
// css: [ './assets/css/tailwind.css'
// ],
// app: {
// pageTransition: {
// name: 'page',
// mode: 'out-in'
// }
// },
runtimeConfig: {
public: {
url: process.env.NUXT_PUBLIC_URL,
Expand Down
3 changes: 0 additions & 3 deletions pages/admin/[episodeslug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const {on_mounted, on_before, on_user_changed} = useMounted(refresh, user, true)
onMounted( on_mounted )
onBeforeMount( on_before )
watch(user, on_user_changed);
onBeforeUpdate(()=> {
console.log("Hi")
refresh()})
const myFetch = useFetchApi()
const router = useRouter()
Expand Down
2 changes: 1 addition & 1 deletion pages/admin/new-serie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const serie = ref(emptyISerieFactory());
const router = useRouter();
async function save(slug: string) {
router.push("/series");
router.push("/series?refresh=true");
}
function cancel() {
Expand Down

0 comments on commit 8e1ad55

Please sign in to comment.