falla desde api

This commit is contained in:
abiandev
2026-05-06 17:44:28 +02:00
parent e56ff9e2c8
commit 5a5ba850ba
7 changed files with 822 additions and 6 deletions
+40 -2
View File
@@ -6,10 +6,47 @@ const DEFAULT_SFTP_PORT = 22;
let sftpClientFactoryOverride = null;
const getTripStatusUploadsDir = () =>
process.env.TRIP_STATUS_UPLOAD_DIR ||
const PRIMARY_TRIP_STATUS_UPLOAD_DIR =
'/var/www/vhosts/gestion.abianservice.com/httpdocs/produccion/app/fotos_estado_react_native/trips/status';
const FALLBACK_TRIP_STATUS_UPLOAD_DIR =
path.resolve(__dirname, '..', '..', 'uploads', 'trips', 'status');
const resolveUploadDirCandidate = (uploadDir) =>
path.isAbsolute(uploadDir)
? uploadDir
: path.resolve(__dirname, '..', '..', uploadDir);
const getExistingAncestorScore = (targetPath) => {
let currentPath = targetPath;
let score = 0;
while (currentPath && currentPath !== path.dirname(currentPath)) {
if (fs.existsSync(currentPath)) {
return score;
}
currentPath = path.dirname(currentPath);
score += 1;
}
return Number.MAX_SAFE_INTEGER;
};
const selectUploadDirCandidate = (uploadDirs) =>
uploadDirs
.map((uploadDir, index) => ({
index,
path: resolveUploadDirCandidate(uploadDir),
score: getExistingAncestorScore(resolveUploadDirCandidate(uploadDir))
}))
.sort((left, right) => left.score - right.score || left.index - right.index)[0]?.path;
const getTripStatusUploadsDir = () => {
return PRIMARY_TRIP_STATUS_UPLOAD_DIR;
};
const getTripStatusFallbackUploadsDir = () => FALLBACK_TRIP_STATUS_UPLOAD_DIR;
const getTripStatusPhotoStorageMode = () =>
String(process.env.TRIP_STATUS_PHOTO_STORAGE_MODE || 'local')
.trim()
@@ -352,6 +389,7 @@ const __resetSftpClientFactoryForTests = () => {
module.exports = {
getTripStatusUploadsDir,
getTripStatusFallbackUploadsDir,
replicateUploadedFilesToRemote,
removeUploadedTripStatusFiles,
removeStatusPhotosByName,