Skip to content

make-screenshots script#15

Open
znarf wants to merge 2 commits intomainfrom
screenshots-script
Open

make-screenshots script#15
znarf wants to merge 2 commits intomainfrom
screenshots-script

Conversation

@znarf
Copy link
Owner

@znarf znarf commented Nov 28, 2023

No description provided.

@znarf znarf requested a review from Copilot October 12, 2025 07:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new make-screenshots script for generating thumbnails/screenshots of bookmarked URLs using an external API service. The script processes marks from a specific user and creates screenshot files while updating the database accordingly.

  • Adds a new screenshot generation script that fetches thumbnails for bookmarked URLs
  • Improves the screenshots table class by adding a create method with automatic timestamp handling
  • Fixes a potential undefined index issue in the marks feed model

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
scripts/make-screenshots.script.php New script for generating screenshots of bookmarked URLs using external API
classes/model/table/screenshots.php Added create method with automatic timestamp handling
classes/model/feed/marks.php Fixed undefined index check for limit parameter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

$folder = date("Y/m/d/" , time() - date('Z') );
$relative = $folder . md5($mark->url) . '.' . $bm_screenshot_extension;
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable $bm_screenshot_extension is undefined. It should be $screenshot_extension which is defined on line 14.

Suggested change
$relative = $folder . md5($mark->url) . '.' . $bm_screenshot_extension;
$relative = $folder . md5($mark->url) . '.' . $screenshot_extension;

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +71
if (!is_dir($screenshot_dir . $folder)) {
error_log("Creating {$folder}");
mkdir($screenshot_dir . $folder, 0777, true);
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable $screenshot_dir is undefined. It should be $screenshot_base_dir which is defined on line 15.

Suggested change
if (!is_dir($screenshot_dir . $folder)) {
error_log("Creating {$folder}");
mkdir($screenshot_dir . $folder, 0777, true);
if (!is_dir($screenshot_base_dir . $folder)) {
error_log("Creating {$folder}");
mkdir($screenshot_base_dir . $folder, 0777, true);

Copilot uses AI. Check for mistakes.

if (!file_exists($screenshot_absolute_path)) {
$parameters = [
'url' => $parsed_url['host'],
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using only the host for the screenshot API may not capture the full page. Consider using $mark->url instead to capture the complete URL including path and query parameters.

Suggested change
'url' => $parsed_url['host'],
'url' => $mark->url,

Copilot uses AI. Check for mistakes.

error_log("Writing {$screenshot_absolute_path}");
file_put_contents($screenshot_absolute_path, $image);
chmod($screenshot_absolute_path, 0777);
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting file permissions to 0777 makes the file world-writable, which is a security risk. Consider using more restrictive permissions like 0644 or 0755.

Suggested change
chmod($screenshot_absolute_path, 0777);
chmod($screenshot_absolute_path, 0644);

Copilot uses AI. Check for mistakes.

$size = strlen($image);
error_log("Size {$size}");
if ($size <= 1252 || $size === 2185 || $size === 1857) {
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic numbers for suspicious file sizes should be defined as named constants or documented with comments explaining what these specific sizes represent.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants