* Creates a share link for a folder. */
(
string $folder,
int $expirationSeconds = 3600,
string $password = "",
int $allowUpload = 0,
int $allowSubfolders = 0,
array $options = []
)
| 2732 | * Creates a share link for a folder. |
| 2733 | */ |
| 2734 | public static function createShareFolderLink( |
| 2735 | string $folder, |
| 2736 | int $expirationSeconds = 3600, |
| 2737 | string $password = "", |
| 2738 | int $allowUpload = 0, |
| 2739 | int $allowSubfolders = 0, |
| 2740 | array $options = [] |
| 2741 | ): array { |
| 2742 | try { |
| 2743 | if (FolderCrypto::isEncryptedOrAncestor($folder)) { |
| 2744 | return ["error" => "Sharing is disabled inside encrypted folders."]; |
| 2745 | } |
| 2746 | } catch (\Throwable $e) { |
| 2747 | /* ignore */ |
| 2748 | } |
| 2749 | |
| 2750 | // Validate folder (and ensure it exists) |
| 2751 | [$real, $relative, $err] = self::resolveFolderPath($folder, false); |
| 2752 | if ($err) { |
| 2753 | return ["error" => $err]; |
| 2754 | } |
| 2755 | |
| 2756 | // Token |
| 2757 | try { |
| 2758 | $token = bin2hex(random_bytes(16)); |
| 2759 | } catch (\Throwable $e) { |
| 2760 | return ["error" => "Could not generate token."]; |
| 2761 | } |
| 2762 | |
| 2763 | $modeRaw = $options['mode'] ?? ''; |
| 2764 | if (($modeRaw === '' || $modeRaw === null) && !empty($options['fileDrop'])) { |
| 2765 | $modeRaw = 'drop'; |
| 2766 | } |
| 2767 | $mode = self::normalizeShareModeValue($modeRaw, false); |
| 2768 | $hideListing = array_key_exists('hideListing', $options) |
| 2769 | ? self::boolFromMixed($options['hideListing']) |
| 2770 | : ($mode === 'drop'); |
| 2771 | $aiEnabled = array_key_exists('aiEnabled', $options) |
| 2772 | ? self::boolFromMixed($options['aiEnabled']) |
| 2773 | : false; |
| 2774 | if ($mode === 'drop') { |
| 2775 | $allowUpload = 1; |
| 2776 | $hideListing = true; |
| 2777 | } |
| 2778 | |
| 2779 | $preserveFolderStructure = array_key_exists('preserveFolderStructure', $options) |
| 2780 | ? self::boolFromMixed($options['preserveFolderStructure']) |
| 2781 | : true; |
| 2782 | $maxFileSizeMb = self::intFromMixed($options['maxFileSizeMb'] ?? 0, 0, 102400); |
| 2783 | $dailyFileLimit = self::intFromMixed($options['dailyFileLimit'] ?? 0, 0, 2000000); |
| 2784 | $maxTotalMbPerDay = self::intFromMixed($options['maxTotalMbPerDay'] ?? 0, 0, 2000000); |
| 2785 | $allowedTypes = self::normalizeShareAllowedTypes($options['allowedTypes'] ?? []); |
| 2786 | $createdBy = trim((string)($options['createdBy'] ?? '')); |
| 2787 | $createdBy = preg_replace('/[\x00-\x1F\x7F]/', '', $createdBy); |
| 2788 | $createdAt = isset($options['createdAt']) && is_numeric($options['createdAt']) |
| 2789 | ? max(0, (int)$options['createdAt']) |
| 2790 | : time(); |
| 2791 |
no test coverage detected