2023-06-29 17:09:18 +02:00
|
|
|
/**
|
|
|
|
* la classe qui repère des patterns
|
|
|
|
*/
|
2023-06-29 18:00:38 +02:00
|
|
|
import {tagSectionSeparator} from "./configs.mjs";
|
2023-06-29 17:09:18 +02:00
|
|
|
|
2023-06-29 18:00:38 +02:00
|
|
|
/**
|
|
|
|
* finds patterns for file name
|
|
|
|
*/
|
2023-06-29 18:13:46 +02:00
|
|
|
export default class finders {
|
2023-06-29 17:09:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
patternsFiles = {
|
|
|
|
'downloaded_pic': /^\-\w{15}\.jpg/, // FyB8cZnWIAc21rw.jpg
|
|
|
|
'telegram_pic': /^\-\d{19}_\d{4}/, // -4900281569878475578_1109.jpg
|
|
|
|
'open_camera': /^IMG_OC_\d{8}/i, // IMG_OC_20230617_092120_3.jpg
|
|
|
|
'screenshot': /^Screenshot/i, // Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png
|
|
|
|
}
|
|
|
|
|
2023-06-29 18:13:46 +02:00
|
|
|
static findScreenshot(inputString) {
|
2023-06-29 17:09:18 +02:00
|
|
|
return inputString.match(/screenshot/i) || inputString.match(/capture d'écran/i)
|
|
|
|
}
|
|
|
|
|
|
|
|
static findFormattedDate(filepath) {
|
2023-06-29 18:13:46 +02:00
|
|
|
let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ig)
|
|
|
|
// console.log('match findFormattedDate', match)
|
|
|
|
let result = ''
|
|
|
|
if (match && match[0]) {
|
|
|
|
result = match[0]
|
|
|
|
}
|
|
|
|
return result
|
2023-06-29 17:09:18 +02:00
|
|
|
}
|
2023-06-29 18:13:46 +02:00
|
|
|
|
|
|
|
static findFileExtension(inputString) {
|
|
|
|
let result = inputString.match(/\.\w{3,4}$/i)
|
|
|
|
// console.log('match findFileExtension', match)
|
|
|
|
// let result = ''
|
|
|
|
// if (match && match[0]) {
|
|
|
|
// result = match[0]
|
|
|
|
// }
|
|
|
|
return result
|
2023-06-29 17:09:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find the section of file name which contains the free text to describe the picture
|
|
|
|
* @param fileName
|
|
|
|
* @returns {*|string}
|
|
|
|
*/
|
|
|
|
static findFileNameFreeTextPart(fileName) {
|
|
|
|
fileName = fileName.replace(this.findFileExtension(fileName), '')
|
|
|
|
let boom = fileName.split(tagSectionSeparator)
|
|
|
|
if (boom.length) {
|
|
|
|
let freeTextPart = boom[0].trim()
|
|
|
|
console.log('freeTextPart', freeTextPart)
|
|
|
|
return freeTextPart
|
|
|
|
}
|
|
|
|
return fileName.trim()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|