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

Freegle / iznik-server / 0a312c38-58e2-4613-9dc7-19fb0c677c25

12 Jun 2024 08:10AM UTC coverage: 94.806% (-0.05%) from 94.856%
0a312c38-58e2-4613-9dc7-19fb0c677c25

push

circleci

edwh
Uploadcare - chat images

1 of 3 new or added lines in 1 file covered. (33.33%)

92 existing lines in 4 files now uncovered.

25424 of 26817 relevant lines covered (94.81%)

31.51 hits per line

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

20.83
/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) {
2✔
10
            $this->config = \Uploadcare\Configuration::create(UPLOADCARE_PUBLIC_KEY, UPLOADCARE_SECRET_KEY);
×
11
            $this->api = (new \Uploadcare\Api($this->config));
×
12
            $this->fileApi = $this->api->file();
×
13
            $this->uploaderApi = $this->api->uploader();
×
14
        }
15
    }
16

17
    function stripExif($uid) {
UNCOV
18
        $oldFileInfo = $this->fileApi->fileInfo($uid);
×
19

20
        # We want to strip the EXIF data.  We remove all of it to avoid any privacy issues.  You have to
21
        # add preview as an operation to make it work.
22
        #
23
        # syncUploadFromUrl guarantees that the image is available on the CDN before returning.
NEW
24
        $newFileInfo = $this->uploaderApi->syncUploadFromUrl(UPLOADCARE_CDN . "$uid/-/strip_meta/all/-/preview/");
×
25
        $newuid = $newFileInfo->getUuid();
×
26
        $this->fileApi->storeFile($newuid);
×
27
        #error_log("Copy $uid, $url to $newuid, $newurl, ready " . $newFileInfo->isReady());
28

29
        if ($newuid) {
×
30
            $this->fileApi->deleteFile($oldFileInfo);
×
31
        }
32

33
        return $newuid;
×
34
    }
35

36
    function getPerceptualHash($uid) {
NEW
37
        $json  = file_get_contents(UPLOADCARE_CDN . "$uid/-/json/");
×
38

39
        if ($json) {
×
40
            $data = json_decode($json, true);
×
41
            return $data['hash'];
×
42
        }
43

44
        return NULL;
×
45
    }
46

47
    function getUrl($uid, $mods) {
48
        # Construct the external URL from the UID and mods.
49
        $url = UPLOADCARE_CDN . "$uid/";
2✔
50
        $mods = json_decode($mods, TRUE);
2✔
51

52
        if ($mods) {
2✔
UNCOV
53
            $url .= '-/';
×
54

UNCOV
55
            foreach ($mods as $mod => $val) {
×
UNCOV
56
                $url .= "$mod/$val/";
×
57
            }
58
        }
59

60
        return $url;
2✔
61
    }
62
}
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