示例#1
0
def generate_image_preview(w, h, path):
    try:
        image = db.get_image(w, h, path)
    except ValueError as e:
        response.status = e.args[0]
        return

    return image
示例#2
0
def get_post(post_id):
    post_info = database.get_post(post_id)
    product_info = database.get_product(post_id)
    image_info = database.get_image(post_id)
    result = json.loads(post_info)
    result[0]["products"] = product_info
    result[0]["images"] = image_info
    print(str(result[0]))
    return json.dumps(result[0])
示例#3
0
def getimg():
    try:
        data = json.loads(request.data)
        print(data.get('id'))
        if data.get('id') == None:
            success = False
        else:
            success = True

        if success == False:
            return json.dumps({"status": "error"})
        else:
            return get_image(data.get('id'))
    except:
        return json.dumps({"status": "error"})
示例#4
0
async def retrieve_image(image_name: str,
                         current_user: Optional[authUtils.User] = Depends(
                             authUtils.optional_get_user_from_token)):
    image_record = database.get_image(image_name)
    if image_record is None:
        raise HTTPException(status_code=404, detail="Image does not exist")
    elif image_record.private:
        if current_user is None:
            raise HTTPException(status_code=401, detail="Not authenticated")
        elif image_record.username != current_user.username:
            raise HTTPException(status_code=401, detail="User not authorized")
        path_prefix = 'private/'
    else:
        path_prefix = 'public/'

    return FileResponse(path_prefix + image_name)
示例#5
0
async def delete_image(image_name: str,
                       current_user: authUtils.User = Depends(
                           authUtils.get_user_from_token)):
    image_record = database.get_image(image_name)
    if image_record is None:
        raise HTTPException(status_code=404, detail="Image does not exist")
    elif image_record.username != current_user.username:
        raise HTTPException(status_code=401, detail="User not authorized")

    if image_record.private:
        path_prefix = 'private/'
        image_search.delete_image(path_prefix + image_name)
    else:
        path_prefix = 'public/'

    database.delete_image(image_name)
    os.remove(path_prefix + image_name)
    return
示例#6
0
    def test_image(self):
        # returns none when image does not exist
        self.assertEqual(None, database.get_image("test"))

        # is able to successfully create image in database
        self.assertEqual(True, create_image("testid", None, False))
        self.assertEqual(True, create_image("testid2", "user", False))
        self.assertEqual(True, create_image("testid3", "user", True))

        # get_image provides correct values
        self.assertEqual(
            ImageInDB(image_id="testid", username=None, private=False),
            database.get_image("testid"))
        self.assertEqual(
            ImageInDB(image_id="testid2", username="******", private=False),
            database.get_image("testid2"))
        self.assertEqual(
            ImageInDB(image_id="testid3", username="******", private=True),
            database.get_image("testid3"))

        # test get image by suer functionality
        self.assertEqual([
            ImageInDB(image_id='testid2', username='******', private=False),
            ImageInDB(image_id='testid3', username='******', private=True)
        ], database.get_images_from_username("user"))
        print()

        # images are deleted properly
        database.delete_image("testid")
        database.delete_image("testid2")
        database.delete_image("testid3")
        self.assertEqual(None, database.get_image("testid"))
        self.assertEqual(None, database.get_image("testid2"))
        self.assertEqual(None, database.get_image("testid3"))

        # fails to create duplicate
        create_image("testid", None, False)
        self.assertEqual(False, create_image("testid", None, False))
        self.assertEqual(False, create_image("testid", "user", False))
        self.assertEqual(False, create_image("testid", "user", True))
def get_image_by_id(id):
	result = database.get_image(id);
	return result[1:];
示例#8
0
def get_image_by_id(id):
    result = database.get_image(id)
    return result[1:]