mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 09:23:00 +02:00
#819 - Added new extensibility support for media scripts
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
# Change Log
|
||||
|
||||
## [10.3.0] - 2024-xx-xx
|
||||
|
||||
### ✨ New features
|
||||
|
||||
### 🎨 Enhancements
|
||||
|
||||
- [#819](https://github.com/estruyf/vscode-front-matter/issues/819): Added new extensibility support for media scripts
|
||||
|
||||
### 🐞 Fixes
|
||||
|
||||
## [10.2.0] - 2024-06-12 - [Release notes](https://beta.frontmatter.codes/updates/v10.2.0)
|
||||
|
||||
### ✨ New features
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Settings } from './SettingsHelper';
|
||||
import { CommandType, EnvironmentType } from './../models/PanelSettings';
|
||||
import { CustomScript as ICustomScript, ScriptType } from '../models/PanelSettings';
|
||||
import { window, env as vscodeEnv, ProgressLocation, Uri, commands } from 'vscode';
|
||||
import { ArticleHelper, Logger, Telemetry } from '.';
|
||||
import { ArticleHelper, Logger, MediaHelpers, Telemetry } from '.';
|
||||
import { Folders, WORKSPACE_PLACEHOLDER } from '../commands/Folders';
|
||||
import { exec, execSync } from 'child_process';
|
||||
import * as os from 'os';
|
||||
@@ -269,7 +269,13 @@ export class CustomScript {
|
||||
): Promise<void> {
|
||||
if (output) {
|
||||
try {
|
||||
const data = JSON.parse(output);
|
||||
const data: {
|
||||
frontmatter?: { [key: string]: any };
|
||||
fmAction?: 'open' | 'copyMediaMetadata' | 'copyMediaMetadataAndDelete' | 'deleteMedia';
|
||||
fmPath?: string;
|
||||
fmSourcePath?: string;
|
||||
fmDestinationPath?: string;
|
||||
} = JSON.parse(output);
|
||||
|
||||
if (data.frontmatter) {
|
||||
let article = null;
|
||||
@@ -305,6 +311,21 @@ export class CustomScript {
|
||||
if (data.fmAction === 'open' && data.fmPath) {
|
||||
const uri = data.fmPath.startsWith(`http`) ? data.fmPath : Uri.file(data.fmPath);
|
||||
commands.executeCommand('vscode.open', uri);
|
||||
} else if (
|
||||
data.fmAction === 'copyMediaMetadata' &&
|
||||
data.fmSourcePath &&
|
||||
data.fmDestinationPath
|
||||
) {
|
||||
await MediaHelpers.copyMetadata(data.fmSourcePath, data.fmDestinationPath);
|
||||
} else if (
|
||||
data.fmAction === 'copyMediaMetadataAndDelete' &&
|
||||
data.fmSourcePath &&
|
||||
data.fmDestinationPath
|
||||
) {
|
||||
await MediaHelpers.copyMetadata(data.fmSourcePath, data.fmDestinationPath);
|
||||
await MediaHelpers.deleteFile(data.fmSourcePath);
|
||||
} else if (data.fmAction === 'deleteMedia' && data.fmPath) {
|
||||
await MediaHelpers.deleteFile(data.fmPath);
|
||||
}
|
||||
} else {
|
||||
Logger.error(`No frontmatter found.`);
|
||||
|
||||
@@ -348,15 +348,7 @@ export class MediaHelpers {
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
public static async deleteFile({
|
||||
file,
|
||||
page,
|
||||
folder
|
||||
}: {
|
||||
file: string;
|
||||
page: number;
|
||||
folder: string | null;
|
||||
}) {
|
||||
public static async deleteFile(file: string) {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
@@ -496,6 +488,18 @@ export class MediaHelpers {
|
||||
await mediaLib.updateFilename(file, filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the metadata from the source media to the target media.
|
||||
*
|
||||
* @param source - The path of the source media.
|
||||
* @param target - The path of the target media.
|
||||
*/
|
||||
public static async copyMetadata(source: string, target: string) {
|
||||
const mediaLib = MediaLibrary.getInstance();
|
||||
const metadata = await mediaLib.get(source);
|
||||
mediaLib.set(target, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the media files
|
||||
*/
|
||||
|
||||
@@ -183,7 +183,7 @@ export class MediaListener extends BaseListener {
|
||||
*/
|
||||
private static delete(data: { file: string; page: number; folder: string | null }) {
|
||||
try {
|
||||
MediaHelpers.deleteFile(data);
|
||||
MediaHelpers.deleteFile(data.file);
|
||||
this.sendMediaFiles(data.page || 0, data.folder || '');
|
||||
} catch {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user