4f00cb2de8
- New nas-paths.ts config: drive mappings, UNC normalization, file:/// URL builder - RegistryAttachment type extended with optional networkPath field - 'Link NAS' button in attachment section opens inline path input - Network path entries shown with blue HardDrive icon + NAS badge - Click opens in Explorer via file:/// URL, copy path button on hover - P:\ auto-converted to \\newamun\Proiecte UNC path - Short display path shows share + last 2 segments - Validation: warns if path doesn't match known NAS mappings
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
/**
|
|
* NAS / network storage path mappings.
|
|
*
|
|
* The office NAS (\\newamun / 10.10.10.10) exposes several shares.
|
|
* Windows maps these to drive letters. This config lets us normalise
|
|
* user-pasted paths to UNC and back, and build clickable `file:///` links.
|
|
*/
|
|
|
|
export interface NasDriveMapping {
|
|
/** Drive letter (upper-case, no colon) */
|
|
drive: string;
|
|
/** UNC prefix WITHOUT trailing backslash, e.g. \\\\newamun\\Proiecte */
|
|
unc: string;
|
|
/** Human-readable label */
|
|
label: string;
|
|
}
|
|
|
|
/** All known drive-letter → UNC mappings */
|
|
export const NAS_DRIVE_MAPPINGS: NasDriveMapping[] = [
|
|
{ drive: "P", unc: "\\\\newamun\\Proiecte", label: "Proiecte" },
|
|
// Add more as needed:
|
|
// { drive: "S", unc: "\\\\newamun\\Shared", label: "Shared" },
|
|
];
|
|
|
|
/** NAS hostname / IP — used for display only */
|
|
export const NAS_HOST = "newamun";
|
|
export const NAS_IP = "10.10.10.10";
|
|
|
|
// ── helpers ──
|
|
|
|
/**
|
|
* Detect whether a string looks like a Windows network / mapped-drive path.
|
|
* Accepts: `P:\folder\file.pdf`, `\\newamun\Proiecte\...`, `\\10.10.10.10\...`
|
|
*/
|
|
export function isNetworkPath(input: string): boolean {
|
|
const trimmed = input.trim();
|
|
// UNC path
|
|
if (trimmed.startsWith("\\\\")) return true;
|
|
// Mapped drive letter that we recognise
|
|
const match = trimmed.match(/^([A-Z]):\\/i);
|
|
if (match) {
|
|
const letter = match[1]!.toUpperCase();
|
|
return NAS_DRIVE_MAPPINGS.some((m) => m.drive === letter);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Normalise to UNC path (replace drive letter with \\newamun\Share).
|
|
* If already UNC or unrecognised → returns the original trimmed.
|
|
*/
|
|
export function toUncPath(input: string): string {
|
|
const trimmed = input.trim();
|
|
if (trimmed.startsWith("\\\\")) return trimmed;
|
|
const match = trimmed.match(/^([A-Z]):(\\.*)/i);
|
|
if (match) {
|
|
const letter = match[1]!.toUpperCase();
|
|
const rest = match[2]!;
|
|
const mapping = NAS_DRIVE_MAPPINGS.find((m) => m.drive === letter);
|
|
if (mapping) return `${mapping.unc}${rest}`;
|
|
}
|
|
return trimmed;
|
|
}
|
|
|
|
/**
|
|
* Build a clickable `file:///` URL from a UNC or drive-letter path.
|
|
* Windows Explorer opens this natively.
|
|
*/
|
|
export function toFileUrl(input: string): string {
|
|
const unc = toUncPath(input);
|
|
// file:///\\server\share\path → file://///server/share/path
|
|
const slashed = unc.replace(/\\/g, "/");
|
|
return `file:///${slashed}`;
|
|
}
|
|
|
|
/**
|
|
* Extract a short display name from a full path.
|
|
* e.g. `\\newamun\Proiecte\095\doc.pdf` → `doc.pdf`
|
|
*/
|
|
export function pathFileName(input: string): string {
|
|
const trimmed = input.trim();
|
|
const parts = trimmed.split(/[\\/]/);
|
|
return parts[parts.length - 1] || trimmed;
|
|
}
|
|
|
|
/**
|
|
* Extract a short display path (share + last 2 segments).
|
|
* e.g. `\\newamun\Proiecte\095 - 2020\99_DOC\file.pdf` → `Proiecte\…\99_DOC\file.pdf`
|
|
*/
|
|
export function shortDisplayPath(input: string): string {
|
|
const unc = toUncPath(input);
|
|
const parts = unc.replace(/^\\\\/, "").split("\\").filter(Boolean);
|
|
// parts: [server, share, folder1, folder2, ..., file]
|
|
if (parts.length <= 3) return parts.slice(1).join("\\");
|
|
const share = parts[1] ?? "";
|
|
const last2 = parts.slice(-2).join("\\");
|
|
return `${share}\\…\\${last2}`;
|
|
}
|