mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
spawnAsync,
|
||||
unescapePath,
|
||||
escapePath,
|
||||
Storage,
|
||||
} from '@google/gemini-cli-core';
|
||||
|
||||
/**
|
||||
@@ -244,19 +245,33 @@ const saveFileWithXclip = async (tempFilePath: string) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the directory where clipboard images should be stored for a specific project.
|
||||
*
|
||||
* This uses the global temporary directory but creates a project-specific subdirectory
|
||||
* based on the hash of the project path (via `Storage.getProjectTempDir()`).
|
||||
* This prevents path conflicts between different projects while keeping the images
|
||||
* outside of the user's project directory.
|
||||
*
|
||||
* @param targetDir The root directory of the current project.
|
||||
* @returns The absolute path to the images directory.
|
||||
*/
|
||||
function getProjectClipboardImagesDir(targetDir: string): string {
|
||||
const storage = new Storage(targetDir);
|
||||
const baseDir = storage.getProjectTempDir();
|
||||
return path.join(baseDir, 'images');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the image from clipboard to a temporary file (macOS, Windows, and Linux)
|
||||
* @param targetDir The target directory to create temp files within
|
||||
* @returns The path to the saved image file, or null if no image or error
|
||||
*/
|
||||
export async function saveClipboardImage(
|
||||
targetDir?: string,
|
||||
targetDir: string,
|
||||
): Promise<string | null> {
|
||||
try {
|
||||
// Create a temporary directory for clipboard images within the target directory
|
||||
// This avoids security restrictions on paths outside the target directory
|
||||
const baseDir = targetDir || process.cwd();
|
||||
const tempDir = path.join(baseDir, '.gemini-clipboard');
|
||||
const tempDir = getProjectClipboardImagesDir(targetDir);
|
||||
await fs.mkdir(tempDir, { recursive: true });
|
||||
|
||||
// Generate a unique filename with timestamp
|
||||
@@ -378,11 +393,10 @@ export async function saveClipboardImage(
|
||||
* @param targetDir The target directory where temp files are stored
|
||||
*/
|
||||
export async function cleanupOldClipboardImages(
|
||||
targetDir?: string,
|
||||
targetDir: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const baseDir = targetDir || process.cwd();
|
||||
const tempDir = path.join(baseDir, '.gemini-clipboard');
|
||||
const tempDir = getProjectClipboardImagesDir(targetDir);
|
||||
const files = await fs.readdir(tempDir);
|
||||
const oneHourAgo = Date.now() - 60 * 60 * 1000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user