From f03737af80372ab6c04742f0e1f9e93b7642b3c8 Mon Sep 17 00:00:00 2001 From: Harald Atteneder Date: Fri, 17 Mar 2023 10:13:00 +0100 Subject: [PATCH 01/12] Update Transcode.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix Craft CMS 4.x filesystems… --- src/services/Transcode.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/Transcode.php b/src/services/Transcode.php index 0a2a69b..f8dc087 100644 --- a/src/services/Transcode.php +++ b/src/services/Transcode.php @@ -787,8 +787,9 @@ protected function getAssetPath(Asset|string $filePath): string if ($assetVolume) { // If it's local, get a path to the file - if ($assetVolume instanceof Local) { - $sourcePath = rtrim($assetVolume->path, DIRECTORY_SEPARATOR); + $fs = $assetVolume->getFs(); + if ($fs instanceof Local) { + $sourcePath = rtrim($fs->path, DIRECTORY_SEPARATOR); $sourcePath .= '' === $sourcePath ? '' : DIRECTORY_SEPARATOR; $folderPath = ''; try { From 9d06103cab077b8f23f95efe3e368ecef6f426ac Mon Sep 17 00:00:00 2001 From: Harald Atteneder Date: Wed, 5 Apr 2023 12:03:31 +0200 Subject: [PATCH 02/12] fix progress URLs --- src/services/Transcode.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/services/Transcode.php b/src/services/Transcode.php index f8dc087..8816588 100644 --- a/src/services/Transcode.php +++ b/src/services/Transcode.php @@ -535,13 +535,13 @@ public function getFileInfo(Asset|string $filePath, bool $summary = false): ?arr /** * Get the name of a video file from a path and options * - * @param string $filePath + * @param Asset|string $filePath * @param array $videoOptions * * @return string * @throws InvalidConfigException */ - public function getVideoFilename(string $filePath, array $videoOptions): string + public function getVideoFilename(Asset|string $filePath, array $videoOptions): string { $settings = Transcoder::$plugin->getSettings(); $videoOptions = $this->coalesceOptions('defaultVideoOptions', $videoOptions); @@ -558,13 +558,13 @@ public function getVideoFilename(string $filePath, array $videoOptions): string /** * Get the name of an audio file from a path and options * - * @param string $filePath + * @param Asset|string $filePath * @param array $audioOptions * * @return string * @throws InvalidConfigException */ - public function getAudioFilename(string $filePath, array $audioOptions): string + public function getAudioFilename(Asset|string $filePath, array $audioOptions): string { $settings = Transcoder::$plugin->getSettings(); $audioOptions = $this->coalesceOptions('defaultAudioOptions', $audioOptions); @@ -581,13 +581,13 @@ public function getAudioFilename(string $filePath, array $audioOptions): string /** * Get the name of a gif video file from a path and options * - * @param string $filePath + * @param Asset|string $filePath * @param array $gifOptions * * @return string * @throws InvalidConfigException */ - public function getGifFilename(string $filePath, array $gifOptions): string + public function getGifFilename(Asset|string $filePath, array $gifOptions): string { $settings = Transcoder::$plugin->getSettings(); $gifOptions = $this->coalesceOptions('defaultGifOptions', $gifOptions); @@ -720,13 +720,13 @@ public function getGifUrl(Asset|string $filePath, array $gifOptions): string|fal /** * Get the name of a file from a path and options * - * @param string $filePath + * @param Asset|string $filePath * @param array $options * * @return string * @throws InvalidConfigException */ - protected function getFilename(string $filePath, array $options): string + protected function getFilename(Asset|string $filePath, array $options): string { $settings = Transcoder::$plugin->getSettings(); $filePath = $this->getAssetPath($filePath); From 761d07cb8ce97df5cf29d45755ee84f11535731a Mon Sep 17 00:00:00 2001 From: Harald Atteneder Date: Wed, 5 Apr 2023 12:04:04 +0200 Subject: [PATCH 03/12] use propper JSON response for actionProgress controller --- src/controllers/DefaultController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index a45769a..ddcd6ff 100644 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -12,12 +12,13 @@ use Craft; use craft\errors\AssetDisallowedExtensionException; -use craft\helpers\Json as JsonHelper; use craft\helpers\Path as PathHelper; use craft\web\Controller; +use craft\web\Response; use nystudio107\transcoder\Transcoder; use yii\base\ExitException; use yii\web\BadRequestHttpException; + use function count; use function is_array; @@ -28,7 +29,6 @@ */ class DefaultController extends Controller { - // Protected Properties // ========================================================================= @@ -100,9 +100,9 @@ public function actionDownloadFile($url): void * * @param $filename * - * @return string + * @return Response */ - public function actionProgress($filename): string + public function actionProgress($filename): Response { $result = []; $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename . '.progress'; @@ -173,6 +173,6 @@ public function actionProgress($filename): string } } - return JsonHelper::encode($result); + return $this->asJson($result); } } From 282d2417e070979aabd1c3d4b90995be101915eb Mon Sep 17 00:00:00 2001 From: Harald Atteneder Date: Wed, 5 Apr 2023 13:27:19 +0200 Subject: [PATCH 04/12] Fix asset thumbnails Return URL instead of path. --- src/services/Transcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/Transcode.php b/src/services/Transcode.php index f8dc087..fe67b1b 100644 --- a/src/services/Transcode.php +++ b/src/services/Transcode.php @@ -615,7 +615,7 @@ public function handleGetAssetThumbPath(DefineAssetThumbUrlEvent $event): null|f 'width' => $event->width, 'height' => $event->height, ]; - return $this->getVideoThumbnailUrl($event->asset, $options, true, true); + return $this->getVideoThumbnailUrl($event->asset, $options); } // Protected Methods From a5328467aefc9819ec66deea95f8a6c40d9387f0 Mon Sep 17 00:00:00 2001 From: Harald Atteneder Date: Wed, 5 Apr 2023 15:07:58 +0200 Subject: [PATCH 05/12] Fix GIF filename generation GIF filename incluced `videoCocecOptions` (e.g. `-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' `) Do not include this param in the filename --- src/services/Transcode.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/Transcode.php b/src/services/Transcode.php index f8dc087..cdc8968 100644 --- a/src/services/Transcode.php +++ b/src/services/Transcode.php @@ -57,6 +57,7 @@ class Transcode extends Component 'sharpen', 'synchronous', 'stripMetadata', + 'videoCodecOptions', ]; // Mappings for getFileInfo() summary values From 376477f29ef390ef48e8e4ceaa0512938b4f30a7 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 18 Apr 2023 17:53:01 -0400 Subject: [PATCH 06/12] chore: Version 4.0.1 --- CHANGELOG.md | 7 +++++++ composer.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ea41d..55960e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Transcoder Changelog +## 4.0.1 - UNRELEASED +### Fixed +* Fix Asset Volume file system access for Craft 4 ([#67](https://github.com/nystudio107/craft-transcoder/pull/67/files)) +* Fix progress URLs and send application/json response ([#68](https://github.com/nystudio107/craft-transcoder/pull/68)) +* Fix asset thumbnails ([#69](https://github.com/nystudio107/craft-transcoder/pull/69)) +* Fix GIF filename generation ([#70](https://github.com/nystudio107/craft-transcoder/pull/70)) + ## 4.0.0 - 2022.09.20 ### Changed * Pinned `vitepress` to `^0.22.4` pending official `1.0.0` release diff --git a/composer.json b/composer.json index 12c15b9..c532467 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-transcoder", "description": "Transcode video & audio files to various formats, and provide video thumbnails", "type": "craft-plugin", - "version": "4.0.0", + "version": "4.0.1", "keywords": [ "craft", "cms", From fa21fcf614eba76b667c3cf038fcdcea84e7e039 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 18 Apr 2023 23:57:40 -0400 Subject: [PATCH 07/12] refactor: Updated the docs to use VitePress `^1.0.0-alpha.29` --- docs/.gitignore | 2 + docs/Makefile | 80 +- docs/docs/.vitepress/config.js | 30 - docs/docs/.vitepress/config.ts | 54 + .../theme/{SidebarBottom.vue => NYSLogo.vue} | 11 +- docs/docs/.vitepress/theme/custom.css | 4 + docs/docs/.vitepress/theme/index.js | 42 - docs/docs/.vitepress/theme/index.ts | 42 + docs/docs/@types/shims.d.ts | 7 + docs/docs/@types/sitemap-plugin.d.ts | 1 + docs/docs/index.md | 10 +- .../{resources => public}/img/nys-logo.svg | 0 docs/docs/public/img/plugin-logo.svg | 25 + docs/docs/resources/img/plugin-logo.png | Bin 38129 -> 0 bytes docs/docs/vite.config.js | 26 - docs/docs/vite.config.ts | 34 + docs/package-lock.json | 2379 +++++++++-------- docs/package.json | 5 +- docs/tsconfig.json | 16 + 19 files changed, 1564 insertions(+), 1204 deletions(-) delete mode 100644 docs/docs/.vitepress/config.js create mode 100644 docs/docs/.vitepress/config.ts rename docs/docs/.vitepress/theme/{SidebarBottom.vue => NYSLogo.vue} (81%) delete mode 100644 docs/docs/.vitepress/theme/index.js create mode 100644 docs/docs/.vitepress/theme/index.ts create mode 100644 docs/docs/@types/shims.d.ts create mode 100644 docs/docs/@types/sitemap-plugin.d.ts rename docs/docs/{resources => public}/img/nys-logo.svg (100%) create mode 100644 docs/docs/public/img/plugin-logo.svg delete mode 100644 docs/docs/resources/img/plugin-logo.png delete mode 100644 docs/docs/vite.config.js create mode 100644 docs/docs/vite.config.ts create mode 100644 docs/tsconfig.json diff --git a/docs/.gitignore b/docs/.gitignore index 26d6131..41eaf24 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,2 +1,4 @@ /vendor /node_modules +/docs/.vitepress/dist +/docs/.vitepress/cache diff --git a/docs/Makefile b/docs/Makefile index e7242c9..f0a3588 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,53 +1,47 @@ +MAJOR_VERSION?=4 TAG?=14-alpine -CONTAINER?=$(shell basename $(dir $(CURDIR)))-docs -DOCKERRUN=docker container run \ - --name ${CONTAINER} \ - --rm \ - -p 3002:3002 \ - -t \ - -v "${CURDIR}":/app \ - ${CONTAINER}:${TAG} -DOCSDEST?=../../../sites/nystudio107/web/docs/transcoder +CONTAINER?=$(shell basename $(dir $(CURDIR)))-v${MAJOR_VERSION}-docs +DOCS_DEV_PORT?=400${MAJOR_VERSION} +DOCS_DEST?=../../../sites/nystudio107/web/docs/retour +IMAGE_INFO=$(shell docker image inspect $(CONTAINER):$(TAG)) +IMAGE_NAME=${CONTAINER}:${TAG} +DOCKER_RUN=docker container run --rm -it -v "${CURDIR}":/app -.PHONY: docker build dev fix install lint clean npm +.PHONY: build clean dev fix image-build image-check lint npm ssh -# Start the Docker container -docker: - docker build \ - . \ - -t ${CONTAINER}:${TAG} \ - --build-arg TAG=${TAG} \ - --no-cache -# Build the production docs -build: docker install - ${DOCKERRUN} \ - run docs:build - rm -rf ${DOCSDEST} - mv ./docs/.vitepress/dist ${DOCSDEST} -# Start up the dev server -dev: docker install - ${DOCKERRUN} \ - run docs:dev -# Fix the docs via textlint -fix: docker install - ${DOCKERRUN} \ - run docs:fix -# Run an npm install -install: docker - ${DOCKERRUN} \ - install -# Lint the docs via textlint -lint: docker install - ${DOCKERRUN} \ - run docs:lint -# Remove node_modules/* & package-lock.json +# Perform a dist build via npm run docs:build +build: image-check + ${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} run docs:build + rm -rf ${DOCS_DEST} + mv ./docs/.vitepress/dist ${DOCS_DEST} +# Remove node_modules/ & package-lock.json clean: rm -rf node_modules/ rm -f package-lock.json +# Run the development server via npm run docs:dev +dev: image-check + ${DOCKER_RUN} --name ${CONTAINER}-$@ -e DOCS_DEV_PORT="${DOCS_DEV_PORT}" -p ${DOCS_DEV_PORT}:${DOCS_DEV_PORT} ${IMAGE_NAME} run docs:dev +# Fix the docs with textlint via npm run docs:fix +fix: image-check + ${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} run docs:fix +# Build the Docker image & run npm install +image-build: + docker build . -t ${IMAGE_NAME} --build-arg TAG=${TAG} --no-cache + ${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} install +# Ensure the image has been created +image-check: +ifeq ($(IMAGE_INFO), []) +image-check: image-build +endif +# Lint the docs with textlint via npm run docs:lint +lint: image-check + ${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} run docs:lint # Run the passed in npm command -npm: docker - ${DOCKERRUN} \ - $(filter-out $@,$(MAKECMDGOALS)) +npm: image-check + ${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} $(filter-out $@,$(MAKECMDGOALS)) $(MAKEFLAGS) +# Open a shell inside of the container +ssh: image-check + ${DOCKER_RUN} --name ${CONTAINER}-$@ --entrypoint=/bin/sh ${IMAGE_NAME} %: @: # ref: https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line diff --git a/docs/docs/.vitepress/config.js b/docs/docs/.vitepress/config.js deleted file mode 100644 index f42e145..0000000 --- a/docs/docs/.vitepress/config.js +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = { - title: 'Transcoder Plugin Documentation', - description: 'Documentation for the Transcoder plugin', - base: '/docs/transcoder/', - lang: 'en-US', - head: [ - ['meta', {content: 'https://github.com/nystudio107', property: 'og:see_also',}], - ['meta', {content: 'https://www.youtube.com/channel/UCOZTZHQdC-unTERO7LRS6FA', property: 'og:see_also',}], - ['meta', {content: 'https://www.facebook.com/newyorkstudio107', property: 'og:see_also',}], - ], - themeConfig: { - repo: 'nystudio107/craft-transcoder', - docsDir: 'docs/docs', - docsBranch: 'develop', - algolia: { - appId: 'VWUWF9S521', - apiKey: 'db5c03f88e474cbf0356841089be7ffa', - indexName: 'transcoder' - }, - editLinks: true, - editLinkText: 'Edit this page on GitHub', - lastUpdated: 'Last Updated', - sidebar: [ - {text: 'Transcoder Plugin', link: '/'}, - {text: 'Transcoder Overview', link: '/overview.html'}, - {text: 'Configuring Transcoder', link: '/configuring.html'}, - {text: 'Using Transcoder', link: '/using.html'}, - ], - }, -}; diff --git a/docs/docs/.vitepress/config.ts b/docs/docs/.vitepress/config.ts new file mode 100644 index 0000000..6d74db9 --- /dev/null +++ b/docs/docs/.vitepress/config.ts @@ -0,0 +1,54 @@ +import {defineConfig} from 'vitepress' + +export default defineConfig({ + title: 'Transcoder Plugin', + description: 'Documentation for the Transcoder plugin', + base: '/docs/transcoder/', + lang: 'en-US', + head: [ + ['meta', {content: 'https://github.com/nystudio107', property: 'og:see_also',}], + ['meta', {content: 'https://twitter.com/nystudio107', property: 'og:see_also',}], + ['meta', {content: 'https://youtube.com/nystudio107', property: 'og:see_also',}], + ['meta', {content: 'https://www.facebook.com/newyorkstudio107', property: 'og:see_also',}], + ], + themeConfig: { + socialLinks: [ + {icon: 'github', link: 'https://github.com/nystudio107'}, + {icon: 'twitter', link: 'https://twitter.com/nystudio107'}, + ], + logo: '/img/plugin-logo.svg', + editLink: { + pattern: 'https://github.com/nystudio107/craft-transcoder/edit/develop/docs/docs/:path', + text: 'Edit this page on GitHub' + }, + algolia: { + appId: 'VWUWF9S521', + apiKey: 'db5c03f88e474cbf0356841089be7ffa', + indexName: 'transcoder' + }, + lastUpdatedText: 'Last Updated', + sidebar: [ + { + text: 'Topics', + items: [ + {text: 'Transcoder Plugin', link: '/'}, + {text: 'Transcoder Overview', link: '/overview.html'}, + {text: 'Configuring Transcoder', link: '/configuring.html'}, + {text: 'Using Transcoder', link: '/using.html'}, + ], + } + ], + nav: [ + {text: 'Home', link: 'https://nystudio107.com/plugins/transcoder'}, + {text: 'Store', link: 'https://plugins.craftcms.com/transcoder'}, + {text: 'Changelog', link: 'https://nystudio107.com/plugins/transcoder/changelog'}, + {text: 'Issues', link: 'https://github.com/nystudio107/craft-transcoder/issues'}, + { + text: 'v4', items: [ + {text: 'v4', link: '/'}, + {text: 'v3', link: 'https://nystudio107.com/docs/transcoder/v3/'}, + ], + }, + ], + }, +}); diff --git a/docs/docs/.vitepress/theme/SidebarBottom.vue b/docs/docs/.vitepress/theme/NYSLogo.vue similarity index 81% rename from docs/docs/.vitepress/theme/SidebarBottom.vue rename to docs/docs/.vitepress/theme/NYSLogo.vue index a2691f3..5a69068 100644 --- a/docs/docs/.vitepress/theme/SidebarBottom.vue +++ b/docs/docs/.vitepress/theme/NYSLogo.vue @@ -6,18 +6,15 @@ target="_blank" rel="noopener" > - + /> -