def post(self): bucketname = self.request.get('bucketname') selfBucket = self.request.get('selfBucket') messageURLs = [] objectNames = [] try: keytext = open(conf.PRIVATE_KEY_PATH, 'rb').read() except IOError as e: sys.exit('Error while reading private key: %s' % e) private_key = RSA.importKey(keytext) signer = CloudStorageURLSigner(private_key, conf.SERVICE_ACCOUNT_EMAIL, GCS_API_ENDPOINT) folder = 'videoMesseagesFrom' + bucketname for object in gs_conn.get_bucket(selfBucket): if folder in object.name: objectname = object.name """Sign url then add it to an array to be returned""" file_path = '/%s/%s' % (selfBucket, objectname) r = signer._MakeUrlForApp('GET', file_path) messageURLs.append(r) """Add the object name to the array""" objectNames.append(object.name) self.response.headers['Content-Type'] = 'application/json' obj = {'signedURLS': messageURLs, 'objectNames': objectNames} self.response.out.write(json.dumps(obj))
def get(self): bucketname = self.request.get('bucketname') signedURLS = [] try: keytext = open(conf.PRIVATE_KEY_PATH, 'rb').read() except IOError as e: sys.exit('Error while reading private key: %s' % e) private_key = RSA.importKey(keytext) signer = CloudStorageURLSigner(private_key, conf.SERVICE_ACCOUNT_EMAIL, GCS_API_ENDPOINT) for object in gs_conn.get_bucket(bucketname): if 'Profile_Videos/' in object.name: print object.name objectname = object.name """Sign url then add it to an array to be returned""" file_path = '/%s/%s' % (bucketname, objectname) r = signer._MakeUrlForApp('GET', file_path) signedURLS.append(r) if object.name == "Profile_Videos/": signedURLS.pop() self.response.headers['Content-Type'] = 'application/json' obj = {'signedURLS': signedURLS} self.response.out.write(json.dumps(obj))
def post(self): selfBucket = self.request.get('selfBucket') objectname = self.request.get('objectname') for object in gs_conn.get_bucket(selfBucket): """Delete the video that was just watched""" if object.name == objectname: object.delete()
def post(self): userbucket = self.request.get('bucketName') """Delete all objects in bucket""" for object in gs_conn.get_bucket(userbucket): object.delete() """Delete their bucket""" gs_conn.delete_bucket(userbucket) """Delete their entity from data store""" r = User.query(User.user_bucket == userbucket) for i in r.fetch(): i.key.delete()
def get(self): print 'the joke is on you' bucketname = self.request.get('bucketname') print bucketname count = 0 for obj in gs_conn.get_bucket(bucketname): print obj.name self.response.headers['Content-Type'] = 'application/json' obj = {'objectname%s' % count: obj.name} self.response.out.write(json.dumps(obj)) count += 1 if count == 1: break
def post(self): bucketname = self.request.get('bucketname') buckets = [] print bucketname for object in gs_conn.get_bucket(bucketname): if 'videoMesseagesFrom' in object.name: """Grab the bucket name""" bucketName = object.name number = bucketName.index("/") bucketName = bucketName[0:number] bucketName = bucketName[18:] """Add bucket to the array""" if bucketName not in buckets: print buckets print bucketName + 'is not already in this bucket' buckets.append(bucketName) self.response.headers['Content-Type'] = 'application/json' obj = {'buckets': buckets} self.response.out.write(json.dumps(obj))
def signProfileVideoUrls(user_bucket): profileVideosObjectnames = [] signedUrls = [] empty = False try: keytext = open(conf.PRIVATE_KEY_PATH, 'rb').read() except IOError as e: sys.exit('Error while reading private key: %s' % e) private_key = RSA.importKey(keytext) signer = CloudStorageURLSigner(private_key, conf.SERVICE_ACCOUNT_EMAIL, GCS_API_ENDPOINT) print user_bucket """Get the initial profile video of the bucket""" for object in gs_conn.get_bucket(user_bucket): if 'Profile_Videos/' in object.name: objectname = object.name profileVideosObjectnames.append(objectname) if object.name == "Profile_Videos/": profileVideosObjectnames.pop() """Signs all of the objects in the array, should be three max""" if not profileVideosObjectnames: print "List is empty" """add is empty to the user's initial video to remove them from the que""" empty = True else: for i in profileVideosObjectnames: """Sign url then add it to the user's initial videos property""" file_path = '/%s/%s' % (user_bucket, i) r = signer._MakeUrlForApp('GET', file_path) """append it to an array""" signedUrls.append(r) """Add signed url to the user that was passed in""" j = User.query(User.user_bucket == user_bucket) for q in j.fetch(): if empty == False: q.profile_video_urls = signedUrls else: print 'do nothing'
def makeGifarray(user_bucket): gifArray = [] signedUrls = [] try: keytext = open(conf.PRIVATE_KEY_PATH, 'rb').read() except IOError as e: sys.exit('Error while reading private key: %s' % e) private_key = RSA.importKey(keytext) signer = CloudStorageURLSigner(private_key, conf.SERVICE_ACCOUNT_EMAIL, GCS_API_ENDPOINT) for i in gs_conn.get_bucket(user_bucket): if 'Profile_Images_For_Gif/' in i.name: gifArray.append(i.name) if i.name == "Profile_Images_For_Gif/": gifArray.pop() for i in gifArray: file_path = '/%s/%s' % (user_bucket, i) r = signer._MakeUrlForApp('GET', file_path) signedUrls.append(r) return signedUrls