url:screenshot:user-data

This commit is contained in:
lovebird 2025-03-29 17:07:05 +01:00
parent 0086189e08
commit cbb7b83ae5
7 changed files with 23 additions and 16 deletions

View File

@ -23,7 +23,7 @@
"format": "unix-time" "format": "unix-time"
} }
], ],
"default": "2025-03-29T15:12:49.089Z" "default": "2025-03-29T16:05:34.037Z"
}, },
"description": { "description": {
"type": "string", "type": "string",

View File

@ -670,7 +670,7 @@
}, },
"https://scholarworks.uni.edu/cgi/viewcontent.cgi?article=3680%5C&context=grp": { "https://scholarworks.uni.edu/cgi/viewcontent.cgi?article=3680%5C&context=grp": {
"isValid": false, "isValid": false,
"timestamp": 1743261170564 "timestamp": 1743264335400
}, },
"https://pmc.ncbi.nlm.nih.gov/articles/PMC10489002/": { "https://pmc.ncbi.nlm.nih.gov/articles/PMC10489002/": {
"isValid": true, "isValid": true,
@ -754,7 +754,7 @@
}, },
"https://journals.plos.org/plosone/article?id=10.1371%252Fjournal.pone.0288696": { "https://journals.plos.org/plosone/article?id=10.1371%252Fjournal.pone.0288696": {
"isValid": false, "isValid": false,
"timestamp": 1743261171019 "timestamp": 1743264335845
}, },
"https://www.youtube.com/watch?v=_a7usMe_K38": { "https://www.youtube.com/watch?v=_a7usMe_K38": {
"isValid": true, "isValid": true,
@ -841,7 +841,7 @@
}, },
"https://www.toraytac.com/media/c3feb206-1398-4e0e-bca6-df7780f11745/tcCurg/TenCate%2520Advanced%2520Composites/Documents/Technical%2520papers/TenCate_chopped_fiber_thermoplastics_compression_molding_technical_paper.pdf": { "https://www.toraytac.com/media/c3feb206-1398-4e0e-bca6-df7780f11745/tcCurg/TenCate%2520Advanced%2520Composites/Documents/Technical%2520papers/TenCate_chopped_fiber_thermoplastics_compression_molding_technical_paper.pdf": {
"isValid": false, "isValid": false,
"timestamp": 1743261171190 "timestamp": 1743264336017
}, },
"https://youtu.be/qtZv96cifIU": { "https://youtu.be/qtZv96cifIU": {
"isValid": true, "isValid": true,

3
.gitignore vendored
View File

@ -1,9 +1,8 @@
# Build output # Build output
dist/ dist/
# Dependencies # Dependencies
node_modules/ node_modules/
.cache/chromium
# Logs # Logs
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*

View File

@ -31,7 +31,7 @@ export default defineConfig({
enabled: false, enabled: false,
}, },
i18n: { i18n: {
locales: ["en"], locales: ["en","es"],
defaultLocale: "en", defaultLocale: "en",
}, },
alias: { alias: {

View File

@ -96,19 +96,13 @@ describe('URL Checker', () => {
}); });
}); });
}); });
describe('checkUrl convenience function', () => {
it('should use the default checker', async () => {
const result = await checkUrl('https://example.com');
expect(result.valid).toBe(true);
});
});
}); });
describe('url screenshot', () => { describe('url screenshot', () => {
const testUrl = 'https://www.youtube.com/watch?v=4LrrFz802To'; const testUrl = 'https://www.youtube.com/watch?v=4LrrFz802To';
const testOutputDir = path.join(__dirname, '../../test-output'); const testOutputDir = path.join(__dirname, '../../test-output');
const screenshotPath = path.join(testOutputDir, 'test-screenshot.png'); const screenshotPath = path.join(testOutputDir, 'test-screenshot.png');
const chromiumDir = path.join(process.cwd(), '.cache', 'chromium');
// Create test output directory if it doesn't exist // Create test output directory if it doesn't exist
beforeAll(() => { beforeAll(() => {
@ -130,6 +124,13 @@ describe('url screenshot', () => {
} }
}); });
it('should create and use chromium user data directory', async () => {
await screenshot(testUrl);
expect(fs.existsSync(chromiumDir)).toBe(true);
// Check for typical Chrome profile directories
expect(fs.existsSync(path.join(chromiumDir, 'Default'))).toBe(true);
}, 60000);
it('should take a screenshot with explicit path', async () => { it('should take a screenshot with explicit path', async () => {
const resultPath = await screenshot(testUrl, { const resultPath = await screenshot(testUrl, {
dstPath: screenshotPath, dstPath: screenshotPath,

View File

@ -46,9 +46,16 @@ async function getGlobalBrowser(): Promise<puppeteer.Browser> {
return browserInitPromise; return browserInitPromise;
} }
// Create chromium user data directory if it doesn't exist
const userDataDir = path.join(process.cwd(), '.cache', 'chromium');
if (!fs.existsSync(userDataDir)) {
fs.mkdirSync(userDataDir, { recursive: true });
}
browserInitPromise = puppeteer.launch({ browserInitPromise = puppeteer.launch({
headless: 'new' as any, headless: 'new' as any,
args: ['--ignore-certificate-errors', '--no-sandbox', '--disable-setuid-sandbox'] args: ['--ignore-certificate-errors', '--no-sandbox', '--disable-setuid-sandbox'],
userDataDir
}); });
try { try {

View File

@ -8,7 +8,7 @@ export const OSR_ROOT = () => path.resolve(resolve("${OSR_ROOT}"))
export const LOGGING_NAMESPACE = 'polymech-site' export const LOGGING_NAMESPACE = 'polymech-site'
export const TRANSLATE_CONTENT = true export const TRANSLATE_CONTENT = true
export const LANGUAGES = ['en'] export const LANGUAGES = ['en', 'es']
export const LANGUAGES_SITE = ['en', 'ar', 'de', 'ja', 'es', 'zh', 'fr'] export const LANGUAGES_SITE = ['en', 'ar', 'de', 'ja', 'es', 'zh', 'fr']
export const LANGUAGES_PROD = ['en'] export const LANGUAGES_PROD = ['en']
export const isRTL = (lang) => lang === 'ar' export const isRTL = (lang) => lang === 'ar'