• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Freegle / iznik-server / 418053ef-1b85-44d6-aeef-204bc752e075

26 Jun 2024 12:25PM UTC coverage: 94.239% (-0.6%) from 94.811%
418053ef-1b85-44d6-aeef-204bc752e075

push

circleci

edwh
Test fixes.

0 of 1 new or added line in 1 file covered. (0.0%)

225 existing lines in 5 files now uncovered.

25190 of 26730 relevant lines covered (94.24%)

31.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/include/misc/UploadCare.php
1
<?php
2
namespace Freegle\Iznik;
3

4
class UploadCare {
5
    private $config = NULL;
6
    private $fileApi = NULL;
7

8
    function __construct() {
9
        if (UPLOADCARE_PUBLIC_KEY) {
54✔
10
            $this->config = \Uploadcare\Configuration::create(UPLOADCARE_PUBLIC_KEY, UPLOADCARE_SECRET_KEY);
54✔
11
            $this->api = (new \Uploadcare\Api($this->config));
54✔
12
            $this->fileApi = $this->api->file();
54✔
13
            $this->uploaderApi = $this->api->uploader();
54✔
14
        }
15
    }
16

17
    function upload($data, $mimeType) {
18
        $file = $this->uploaderApi->fromContent($data, $mimeType);
53✔
19
        $uid = $file->getUuid();
53✔
20

21
        return $uid;
53✔
22
    }
23

24
    function stripExif($uid) {
25
        $oldFileInfo = $this->fileApi->fileInfo($uid);
53✔
26

27
        # We want to strip the EXIF data.  We remove all of it to avoid any privacy issues.  You have to
28
        # add preview as an operation to make it work.
29
        #
30
        # syncUploadFromUrl guarantees that the image is available on the CDN before returning.
31
        $newFileInfo = $this->uploaderApi->syncUploadFromUrl(UPLOADCARE_CDN . "$uid/-/strip_meta/all/-/preview/");
53✔
32
        $newuid = $newFileInfo->getUuid();
53✔
33
        $this->fileApi->storeFile($newuid);
53✔
34
        #error_log("Copy $uid, $url to $newuid, $newurl, ready " . $newFileInfo->isReady());
35

36
        if ($newuid) {
53✔
37
            $this->fileApi->deleteFile($oldFileInfo);
53✔
38
        }
39

40
        return $newuid;
53✔
41
    }
42

43
    function getPerceptualHash($uid) {
44
        $json  = file_get_contents(UPLOADCARE_CDN . "$uid/-/json/");
53✔
45

46
        if ($json) {
53✔
47
            $data = json_decode($json, true);
53✔
48
            return $data['hash'];
53✔
49
        }
50

UNCOV
51
        return NULL;
×
52
    }
53

54
    function getUrl($uid, $mods) {
55
        # Construct the external URL from the UID and mods.
56
        $url = UPLOADCARE_CDN . "$uid/";
43✔
57
        $mods = json_decode($mods, TRUE);
43✔
58

59
        if ($mods) {
43✔
60
            foreach ($mods as $mod => $val) {
1✔
61
                $url .= "-/$mod/$val/";
1✔
62
            }
63
        }
64

65
        return $url;
43✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc