Skip to content
Snippets Groups Projects
Unverified Commit fd45e146 authored by Spotlight Deveaux's avatar Spotlight Deveaux :fox:
Browse files

Remove service providers asides from Pomf

parent dcd89c30
No related branches found
No related tags found
No related merge requests found
......@@ -6,14 +6,8 @@ target 'Screenshottr' do
use_frameworks!
# Pods for Screenshottr
pod 'GoogleAPIClientForREST'
pod 'GoogleAPIClientForREST/Storage'
pod 'GTMAppAuth'
pod 'UTIKit'
pod 'SKQueue', :git => 'https://github.com/spotlightishere/SKQueue'
# pod 'AWSCore', :git => 'https://github.com/nickoneill/aws-sdk-osx'
# pod 'AWSS3', :git => 'https://github.com/nickoneill/aws-sdk-osx'
# pod 'ImgurSession', :git => 'https://github.com/mileswd/ImgurSession'
target 'ScreenshottrTests' do
inherit! :search_paths
......
......@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
4241FB4F1FBD106700A364B9 /* Pods_Screenshottr.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 85B58CFFF6F2C5DBA952F077 /* Pods_Screenshottr.framework */; };
4241FB521FBD106800A364B9 /* GoogleAPIClientForREST.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4241FB501FBD106700A364B9 /* GoogleAPIClientForREST.framework */; };
4255DEDE2030A89F00E67FCA /* SettingsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4255DEDD2030A89F00E67FCA /* SettingsView.xib */; };
4277C2BB1F4F66F8004649DA /* PomfManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4277C2BA1F4F66F7004649DA /* PomfManager.swift */; };
4279D5841F4686AE00558889 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4279D5831F4686AE00558889 /* AppDelegate.swift */; };
......@@ -16,7 +15,6 @@
4279D5941F4686AE00558889 /* ScreenshottrTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4279D5931F4686AE00558889 /* ScreenshottrTests.swift */; };
4279D59F1F4686AE00558889 /* ScreenshottrUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4279D59E1F4686AE00558889 /* ScreenshottrUITests.swift */; };
4279D5C61F4696EA00558889 /* UploadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4279D5C51F4696EA00558889 /* UploadManager.swift */; };
4279D5D01F46A01D00558889 /* GCPManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4279D5CF1F46A01D00558889 /* GCPManager.swift */; };
4288972E20028D3F00B2FA08 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4288972D20028D3F00B2FA08 /* SettingsView.swift */; };
42C0AD501FBE5D6D0053C761 /* PopoverMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C0AD4F1FBE5D6D0053C761 /* PopoverMenu.swift */; };
42C0AD521FBE61A70053C761 /* PopoverMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 42C0AD511FBE61A70053C761 /* PopoverMenu.xib */; };
......@@ -61,7 +59,6 @@
4279D59E1F4686AE00558889 /* ScreenshottrUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshottrUITests.swift; sourceTree = "<group>"; };
4279D5A01F4686AE00558889 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4279D5C51F4696EA00558889 /* UploadManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UploadManager.swift; sourceTree = "<group>"; };
4279D5CF1F46A01D00558889 /* GCPManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GCPManager.swift; sourceTree = "<group>"; };
4288972D20028D3F00B2FA08 /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
42C0AD4F1FBE5D6D0053C761 /* PopoverMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopoverMenu.swift; sourceTree = "<group>"; };
42C0AD511FBE61A70053C761 /* PopoverMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PopoverMenu.xib; sourceTree = "<group>"; };
......@@ -79,7 +76,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4241FB521FBD106800A364B9 /* GoogleAPIClientForREST.framework in Frameworks */,
4241FB4F1FBD106700A364B9 /* Pods_Screenshottr.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -132,7 +128,6 @@
4279D5851F4686AE00558889 /* Assets.xcassets */,
4279D58A1F4686AE00558889 /* Info.plist */,
4279D5C51F4696EA00558889 /* UploadManager.swift */,
4279D5CF1F46A01D00558889 /* GCPManager.swift */,
4277C2BA1F4F66F7004649DA /* PomfManager.swift */,
42F2C88A1F4A585B00FA3D44 /* MainMenu.xib */,
4255DEDD2030A89F00E67FCA /* SettingsView.xib */,
......@@ -339,19 +334,11 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Screenshottr/Pods-Screenshottr-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AppAuth/AppAuth.framework",
"${BUILT_PRODUCTS_DIR}/GTMAppAuth/GTMAppAuth.framework",
"${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework",
"${BUILT_PRODUCTS_DIR}/GoogleAPIClientForREST/GoogleAPIClientForREST.framework",
"${BUILT_PRODUCTS_DIR}/SKQueue/SKQueue.framework",
"${BUILT_PRODUCTS_DIR}/UTIKit/UTIKit.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AppAuth.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMAppAuth.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMSessionFetcher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleAPIClientForREST.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SKQueue.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/UTIKit.framework",
);
......@@ -424,7 +411,6 @@
4288972E20028D3F00B2FA08 /* SettingsView.swift in Sources */,
4279D5C61F4696EA00558889 /* UploadManager.swift in Sources */,
42C0AD501FBE5D6D0053C761 /* PopoverMenu.swift in Sources */,
4279D5D01F46A01D00558889 /* GCPManager.swift in Sources */,
4279D5841F4686AE00558889 /* AppDelegate.swift in Sources */,
4277C2BB1F4F66F8004649DA /* PomfManager.swift in Sources */,
);
......
//
// GCPAuthHandler.swift
// Screenshottr
//
// Created by Spotlight on 8/17/17.
// Copyright © 2017 JOS Computing. All rights reserved.
//
import Foundation
import GTMAppAuth
import GoogleAPIClientForREST
import UTIKit
class GCPAuthHandler {
let redirectHTTPHandler = OIDRedirectHTTPHandler(successURL: URL(string: "http://openid.github.io/AppAuth-iOS/redirect/"))
let userDefaults = UserDefaults.standard
func signedIn(service: GTLRStorageService) -> Bool {
let auth = service.authorizer
if (auth == nil) {
return false
}
if (auth?.canAuthorize)! {
let email : String? = auth?.userEmail
if (email != nil) {
print("Signed in with \(email!)")
return true
}
}
// I guess not, return false by default.
return false
}
func runSignin(completionHandler: @escaping (GTLRStorageService) -> Void) {
let authorizedService = GTLRStorageService.init()
authorizedService.shouldFetchNextPages = true
authorizedService.isRetryEnabled = true
let authorization = GTMAppAuthFetcherAuthorization.init(fromKeychainForName: "Screenshottr")
authorizedService.authorizer = authorization
if (!signedIn(service: authorizedService)) {
// Authentication
var httpError : NSError?
let localRedirectURI : URL? = redirectHTTPHandler.startHTTPListener(&httpError)
if (localRedirectURI == nil) {
print("Unexpected error starting redirect handler: \(httpError!)");
// Yes, it's not authorized at this point.
// TODO: figure out something to do with that
return completionHandler(authorizedService);
}
// Builds authentication request.
let scopes : Array<String> = [ kGTLRAuthScopeStorageDevstorageReadWrite, OIDScopeEmail ];
let request = OIDAuthorizationRequest(configuration: GTMAppAuthFetcherAuthorization.configurationForGoogle(),
clientId: userDefaults.string(forKey: "gcpClientID")!,
clientSecret: userDefaults.string(forKey: "gcpClientSecret")!,
scopes: scopes,
redirectURL: localRedirectURI!,
responseType: OIDResponseTypeCode,
additionalParameters: nil)
redirectHTTPHandler.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, callback: {
(authState, redirectError) in
NSRunningApplication.current.activate(options: [.activateAllWindows, .activateIgnoringOtherApps])
if (authState != nil) {
let gtmAuthorization = GTMAppAuthFetcherAuthorization.init(authState: authState!)
authorizedService.authorizer = gtmAuthorization
GTMAppAuthFetcherAuthorization.save(gtmAuthorization, toKeychainForName: "Screenshottr")
completionHandler(authorizedService)
}
})
} else {
completionHandler(authorizedService)
}
}
func uploadFile(path: String, completionHandler: @escaping (_ : NSError?, _ : String) -> Void) {
runSignin {(service: GTLRStorageService) in
print("Uploading \(path)")
let fileURL = URL(fileURLWithPath: path)
// Use UTIKit to grab the first MIME type recorded.
let mimeType = UTI(filenameExtension: fileURL.pathExtension)?.mimeType ?? "application/octet-stream"
print(mimeType)
let uploadParameters = GTLRUploadParameters.init(fileURL: fileURL, mimeType: mimeType)
let newObject = GTLRStorage_Object()
newObject.name = fileURL.lastPathComponent
// Set ACL to public for usage later on.
let query = GTLRStorageQuery_ObjectsInsert.query(with: newObject,
bucket: self.userDefaults.string(forKey: "gcpBucketName")!,
uploadParameters: uploadParameters)
query.predefinedAcl = kGTLRStorageDestinationPredefinedAclPublicRead;
// Output progress to the console
query.executionParameters.uploadProgressBlock = {(callbackTicket: GTLRServiceTicket,
numberOfBytesRead: CUnsignedLongLong,
dataLength: CUnsignedLongLong) -> Void in
print(NSString(format: "We out here, %llu/%llu", numberOfBytesRead, dataLength))
}
service.executeQuery(query) { (callbackTicket, uploadedFile, callbackError) in
let fileURL = NSURL(fileURLWithPath: path)
let escapedFilename = (fileURL.lastPathComponent?.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!)!
completionHandler(callbackError as NSError?, "\(self.userDefaults.string(forKey: "gcpBaseDomain")!)/\(escapedFilename)")
}
}
}
}
......@@ -54,7 +54,7 @@ class UploadManager : NSObject {
}
print("\(toUpload) is uploading...")
for screenshot in toUpload {
uploadWith(provider: type, path: screenshot.path, shouldDelete: true)
uploadFrom(path: screenshot.path, shouldDelete: true)
}
defaults.set(false, forKey: uploadingKey)
} catch let error as NSError {
......@@ -64,23 +64,14 @@ class UploadManager : NSObject {
}
}
} else {
uploadWith(provider: type, path: path, shouldDelete: false)
uploadFrom(path: path, shouldDelete: false)
}
}
func uploadWith(provider: UploadTypes, path: String, shouldDelete: Bool) {
switch (provider) {
case .GoogleCloudPlatform:
GCPAuthHandler().uploadFile(path: path) { (error, url) in
self.finalizeUpload(path: path, error: error, url: url, shouldDelete: shouldDelete) {}
}
break
case .Pomf:
func uploadFrom(path: String, shouldDelete: Bool) {
PomfManager().uploadFile(path: path) { (error, url) in
self.finalizeUpload(path: path, error: error, url: url, shouldDelete: shouldDelete) {}
}
break
}
}
func finalizeUpload(path: String, error: NSError?, url: String, shouldDelete: Bool, handler: () -> Void) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment