Working auth and photo json endpoint

Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
Kris Nóva 2021-02-09 11:17:06 -08:00
parent ef275f97f4
commit e4323b6047
2032 changed files with 821464 additions and 52 deletions

View file

View file

@ -0,0 +1,19 @@
language: go
go:
- master
- stable
- "1.14"
- "1.13"
- "1.12"
env:
- GO111MODULE=on
install:
# v1
- go get -t .
# v2
- cd v2
- go test -v ./... -coverprofile=coverage.txt -covermode=atomic
- cd ..
after_success:
- cd v2
- curl -s https://codecov.io/bash | bash

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Dustin Oprea
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,8 @@
[![Build Status](https://travis-ci.org/dsoprea/go-tiff-image-structure.svg?branch=master)](https://travis-ci.org/dsoprea/go-tiff-image-structure)
[![Coverage Status](https://coveralls.io/repos/github/dsoprea/go-tiff-image-structure/badge.svg?branch=master)](https://coveralls.io/github/dsoprea/go-tiff-image-structure?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/dsoprea/go-tiff-image-structure)](https://goreportcard.com/report/github.com/dsoprea/go-tiff-image-structure)
[![GoDoc](https://godoc.org/github.com/dsoprea/go-tiff-image-structure?status.svg)](https://godoc.org/github.com/dsoprea/go-tiff-image-structure)
## Overview
Parse raw TIFF data.

View file

@ -0,0 +1,9 @@
module github.com/dsoprea/go-tiff-image-structure
go 1.13
require (
github.com/dsoprea/go-exif/v2 v2.0.0-20200604193436-ca8584a0e1c4
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d
github.com/dsoprea/go-utility v0.0.0-20200512094054-1abbbc781176
)

View file

@ -0,0 +1,31 @@
github.com/dsoprea/go-exif v0.0.0-20200602082308-c23f7a10661b h1:mjpe1qfTE5FA1NcfoftTQbNWBA6iergN0qP7YJ4f6O8=
github.com/dsoprea/go-exif/v2 v2.0.0-20200321225314-640175a69fe4/go.mod h1:Lm2lMM2zx8p4a34ZemkaUV95AnMl4ZvLbCUbwOvLC2E=
github.com/dsoprea/go-exif/v2 v2.0.0-20200602082308-c23f7a10661b h1:p8sjPJenU4nLtlHFxzrMguyz3x+xB3qTiZ6k4jYoA1g=
github.com/dsoprea/go-exif/v2 v2.0.0-20200602082308-c23f7a10661b/go.mod h1:9EXlPeHfblFFnwu5UOqmP2eoZfJyAZ2Ri/Vki33ajO0=
github.com/dsoprea/go-exif/v2 v2.0.0-20200604193436-ca8584a0e1c4 h1:Mg7pY7kxDQD2Bkvr1N+XW4BESSIQ7tTTR7Vv+Gi2CsM=
github.com/dsoprea/go-exif/v2 v2.0.0-20200604193436-ca8584a0e1c4/go.mod h1:9EXlPeHfblFFnwu5UOqmP2eoZfJyAZ2Ri/Vki33ajO0=
github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696/go.mod h1:Nm/x2ZUNRW6Fe5C3LxdY1PyZY5wmDv/s5dkPJ/VB3iA=
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d h1:F/7L5wr/fP/SKeO5HuMlNEX9Ipyx2MbH2rV9G4zJRpk=
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d/go.mod h1:7I+3Pe2o/YSU88W0hWlm9S22W7XI1JFNJ86U0zPKMf8=
github.com/dsoprea/go-utility v0.0.0-20200512094054-1abbbc781176 h1:CfXezFYb2STGOd1+n1HshvE191zVx+QX3A1nML5xxME=
github.com/dsoprea/go-utility v0.0.0-20200512094054-1abbbc781176/go.mod h1:95+K3z2L0mqsVYd6yveIv1lmtT3tcQQ3dVakPySffW8=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/go-errors/errors v1.0.2 h1:xMxH9j2fNg/L4hLn/4y3M0IUsn0M6Wbu/Uh9QlOfBh4=
github.com/go-errors/errors v1.0.2/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs=
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d h1:C/hKUcHT483btRbeGkrRjJz+Zbcj8audldIi9tRJDCc=
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120 h1:EZ3cVSzKOlJxAd8e8YAJ7no8nNypTxexh/YE/xW3ZEY=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View file

@ -0,0 +1,122 @@
package tiffstructure
import (
"bytes"
"io"
"os"
"io/ioutil"
"github.com/dsoprea/go-exif/v2"
log "github.com/dsoprea/go-logging"
riimage "github.com/dsoprea/go-utility/image"
)
// TiffMediaParser knows how to parse a TIFF stream.
type TiffMediaParser struct {
}
// NewTiffMediaParser returns a new `TiffMediaParser` struct.
func NewTiffMediaParser() *TiffMediaParser {
return new(TiffMediaParser)
}
// TiffMediaContext encapsulates parsed EXIF data.
type TiffMediaContext struct {
rootIfd *exif.Ifd
data []byte
}
// Exif is an accessor that returns the root IFD.
func (tmc *TiffMediaContext) Exif() (rootIfd *exif.Ifd, data []byte, err error) {
// TODO(dustin): Add test
return tmc.rootIfd, tmc.data, nil
}
// Parse parses a TIFF stream given a `io.ReadSeeker`.
func (tmp *TiffMediaParser) Parse(rs io.ReadSeeker, size int) (mc riimage.MediaContext, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
exifData, err := ioutil.ReadAll(rs)
log.PanicIf(err)
im := exif.NewIfdMappingWithStandard()
ti := exif.NewTagIndex()
_, index, err := exif.Collect(im, ti, exifData)
log.PanicIf(err)
tmc := &TiffMediaContext{
rootIfd: index.RootIfd,
data: exifData,
}
return tmc, nil
}
// ParseFile parses a TIFF stream given a file-path.
func (tmp *TiffMediaParser) ParseFile(filepath string) (mc riimage.MediaContext, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
f, err := os.Open(filepath)
log.PanicIf(err)
defer f.Close()
stat, err := f.Stat()
log.PanicIf(err)
size := stat.Size()
mc, err = tmp.Parse(f, int(size))
log.PanicIf(err)
return mc, nil
}
// ParseBytes parses a TIFF stream given a byte-slice.
func (tmp *TiffMediaParser) ParseBytes(data []byte) (mc riimage.MediaContext, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
// TODO(dustin): Add test
br := bytes.NewReader(data)
mc, err = tmp.Parse(br, len(data))
log.PanicIf(err)
return mc, nil
}
// LooksLikeFormat returns a boolean indicating whether this looks like a TIFF
// stream.
func (tmp *TiffMediaParser) LooksLikeFormat(data []byte) bool {
if len(data) < exif.ExifSignatureLength {
return false
}
// TODO(dustin): Add test
_, err := exif.ParseExifHeader(data)
return err == nil
}
var (
// Enforce interface conformance.
_ riimage.MediaParser = new(TiffMediaParser)
_ riimage.MediaContext = new(TiffMediaContext)
)

View file

@ -0,0 +1,64 @@
package tiffstructure
import (
"os"
"path"
log "github.com/dsoprea/go-logging"
)
var (
assetsPath = ""
)
// getModuleRootPath returns our source-path when running from source during
// tests.
func getModuleRootPath() string {
moduleRootPath := os.Getenv("TIFF_MODULE_ROOT_PATH")
if moduleRootPath != "" {
return moduleRootPath
}
currentWd, err := os.Getwd()
log.PanicIf(err)
currentPath := currentWd
visited := make([]string, 0)
for {
tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
_, err := os.Stat(tryStampFilepath)
if err != nil && os.IsNotExist(err) != true {
log.Panic(err)
} else if err == nil {
break
}
visited = append(visited, tryStampFilepath)
currentPath = path.Dir(currentPath)
if currentPath == "/" {
log.Panicf("could not find module-root: %v", visited)
}
}
return currentPath
}
// getTestAssetsPath returns the test-asset path.
func getTestAssetsPath() string {
if assetsPath == "" {
moduleRootPath := getModuleRootPath()
assetsPath = path.Join(moduleRootPath, "assets")
}
return assetsPath
}
// getTestExifImageFilepath returns the file-path of the default EXIF image
// asset.
func getTestExifImageFilepath() string {
assetsPath := getTestAssetsPath()
return path.Join(assetsPath, "file_example_TIFF_1MB-scaled.tiff")
}