Work on hosted files and archives.
This commit is contained in:
@@ -11,18 +11,22 @@ from app.models.common_field_schema import base_fields, default_num_bytes
|
|||||||
|
|
||||||
# ### BEGIN ### API Archive Content Models ### Archive_Content_Base() ###
|
# ### BEGIN ### API Archive Content Models ### Archive_Content_Base() ###
|
||||||
class Archive_Content_Base(BaseModel):
|
class Archive_Content_Base(BaseModel):
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
|
def testing(test_var=None):
|
||||||
|
log.debug(test_var)
|
||||||
|
return test_var
|
||||||
|
|
||||||
id_random: Optional[str] = Field(
|
id_random: Optional[str] = Field(
|
||||||
**base_fields['archive_content_id_random'],
|
# **base_fields['archive_content_id_random'],
|
||||||
alias = 'archive_content_id_random',
|
alias = 'archive_content_id_random',
|
||||||
)
|
)
|
||||||
id: Optional[int] = Field(
|
id: Optional[int] = Field(
|
||||||
alias = 'archive_content_id'
|
alias = 'archive_content_id'
|
||||||
)
|
)
|
||||||
account_id_random: Optional[str] # Is this field really needed?
|
# account_id_random: Optional[str] # Is this field really needed?
|
||||||
account_id: Optional[int] # Is this field really needed?
|
# account_id: Optional[int] # Is this field really needed?
|
||||||
|
|
||||||
archive_id_random: Optional[str]
|
archive_id_random: Optional[str]
|
||||||
archive_id: Optional[int]
|
archive_id: Optional[int]
|
||||||
@@ -45,9 +49,16 @@ class Archive_Content_Base(BaseModel):
|
|||||||
hosted_file_id: Optional[int]
|
hosted_file_id: Optional[int]
|
||||||
|
|
||||||
file_path: Optional[str]
|
file_path: Optional[str]
|
||||||
|
|
||||||
filename: Optional[str]
|
filename: Optional[str]
|
||||||
file_extension: Optional[str]
|
file_extension: Optional[str]
|
||||||
|
|
||||||
|
# xxxx_red: str = Field(default='xxx')
|
||||||
|
# xxxx_blue: str = Field(default_factory=testing)
|
||||||
|
hosted_file_path: str = None # '/testing/test-test'
|
||||||
|
|
||||||
|
wtf: str = 'HELLO???'
|
||||||
|
|
||||||
original_datetime: Optional[datetime.datetime]
|
original_datetime: Optional[datetime.datetime]
|
||||||
original_datetime_timezone: Optional[str]
|
original_datetime_timezone: Optional[str]
|
||||||
original_location: Optional[str]
|
original_location: Optional[str]
|
||||||
@@ -72,45 +83,58 @@ class Archive_Content_Base(BaseModel):
|
|||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
#@validator('archive_content_id_random', always=True)
|
|
||||||
def archive_content_id_random_copy(cls, v, values, **kwargs):
|
|
||||||
log.setLevel(logging.WARNING)
|
|
||||||
log.debug(locals())
|
|
||||||
|
|
||||||
if values['id_random']:
|
|
||||||
return values['id_random']
|
|
||||||
return None
|
|
||||||
|
|
||||||
@validator('id', always=True)
|
@validator('id', always=True)
|
||||||
def archive_content_id_lookup(cls, v, values, **kwargs):
|
def archive_content_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
if isinstance(v, int) and v > 0: return v
|
||||||
log.debug(locals())
|
elif id_random := values.get('id_random'):
|
||||||
|
return redis_lookup_id_random(record_id_random=id_random, table_name='archive_content')
|
||||||
if values['id_random']:
|
|
||||||
log.debug(values['id_random'])
|
|
||||||
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='archive_content')
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@validator('archive_id', always=True)
|
@validator('archive_id', always=True)
|
||||||
def archive_id_lookup(cls, v, values, **kwargs):
|
def archive_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
if isinstance(v, int) and v > 0: return v
|
||||||
log.debug(locals())
|
elif id_random := values.get('archive_id_random'):
|
||||||
|
return redis_lookup_id_random(record_id_random=id_random, table_name='archive')
|
||||||
if values['archive_id_random']:
|
|
||||||
return redis_lookup_id_random(record_id_random=values['archive_id_random'], table_name='archive')
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@validator('account_id', always=True)
|
@validator('hosted_file_id', always=True)
|
||||||
def account_id_lookup(cls, v, values, **kwargs):
|
def hosted_file_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
if isinstance(v, int) and v > 0: return v
|
||||||
log.debug(locals())
|
elif id_random := values.get('hosted_file_id_random'):
|
||||||
|
return redis_lookup_id_random(record_id_random=id_random, table_name='hosted_file')
|
||||||
if values['account_id_random']:
|
|
||||||
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@validator('hosted_file_path', always=True)
|
||||||
|
def hosted_file_path_lookup(cls, v, values, **kwargs):
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(v)
|
||||||
|
log.debug(values)
|
||||||
|
|
||||||
|
if hosted_file_id_random := values.get('hosted_file_id_random'):
|
||||||
|
log.debug('Found hosted_file_id_random...')
|
||||||
|
path_str = f'/hosted_file/download/{hosted_file_id_random}'
|
||||||
|
|
||||||
|
if filename := values.get('filename'):
|
||||||
|
path_str = f'{path_str}?filename={filename}'
|
||||||
|
|
||||||
|
log.debug(path_str)
|
||||||
|
return path_str
|
||||||
|
log.debug('NOT Found hosted_file_id_random...')
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# @validator('account_id', always=True)
|
||||||
|
# def account_id_lookup(cls, v, values, **kwargs):
|
||||||
|
# log.setLevel(logging.WARNING)
|
||||||
|
# log.debug(locals())
|
||||||
|
|
||||||
|
# if values['account_id_random']:
|
||||||
|
# return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
||||||
|
# return None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
underscore_attrs_are_private = True
|
underscore_attrs_are_private = True
|
||||||
allow_population_by_field_name = True
|
allow_population_by_field_name = True
|
||||||
fields = base_fields
|
fields = base_fields
|
||||||
# ### END ### API Archive Content Models ### Archive_Content_Base() ###
|
# ### END ### API Archive Content Models ### Archive_Content_Base() ###
|
||||||
|
|||||||
@@ -65,36 +65,22 @@ class Archive_Base(BaseModel):
|
|||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
#@validator('archive_id_random', always=True)
|
|
||||||
def archive_id_random_copy(cls, v, values, **kwargs):
|
|
||||||
log.setLevel(logging.WARNING)
|
|
||||||
log.debug(locals())
|
|
||||||
|
|
||||||
if values['id_random']:
|
|
||||||
return values['id_random']
|
|
||||||
return None
|
|
||||||
|
|
||||||
@validator('id', always=True)
|
@validator('id', always=True)
|
||||||
def archive_id_lookup(cls, v, values, **kwargs):
|
def archive_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
if isinstance(v, int) and v > 0: return v
|
||||||
log.debug(locals())
|
elif id_random := values.get('id_random'):
|
||||||
|
return redis_lookup_id_random(record_id_random=id_random, table_name='archive')
|
||||||
if values['id_random']:
|
|
||||||
log.debug(values['id_random'])
|
|
||||||
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='archive')
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@validator('account_id', always=True)
|
@validator('account_id', always=True)
|
||||||
def account_id_lookup(cls, v, values, **kwargs):
|
def account_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
if isinstance(v, int) and v > 0: return v
|
||||||
log.debug(locals())
|
elif id_random := values.get('account_id_random'):
|
||||||
|
return redis_lookup_id_random(record_id_random=id_random, table_name='account')
|
||||||
if values['account_id_random']:
|
|
||||||
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
underscore_attrs_are_private = True
|
underscore_attrs_are_private = True
|
||||||
allow_population_by_field_name = True
|
allow_population_by_field_name = True
|
||||||
fields = base_fields
|
fields = base_fields
|
||||||
# ### END ### API Archive Models ### Archive_Base() ###
|
# ### END ### API Archive Models ### Archive_Base() ###
|
||||||
|
|||||||
@@ -68,12 +68,6 @@ class Data_Store_Base(BaseModel):
|
|||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
#@validator('data_store_id_random', always=True)
|
|
||||||
def data_store_id_random_copy(cls, v, values, **kwargs):
|
|
||||||
if values['id_random']:
|
|
||||||
return values['id_random']
|
|
||||||
return None
|
|
||||||
|
|
||||||
@validator('id', always=True)
|
@validator('id', always=True)
|
||||||
def data_store_id_lookup(cls, v, values, **kwargs):
|
def data_store_id_lookup(cls, v, values, **kwargs):
|
||||||
if isinstance(v, int) and v > 0: return v
|
if isinstance(v, int) and v > 0: return v
|
||||||
|
|||||||
@@ -88,14 +88,14 @@ async def get_archive_content_obj_li(
|
|||||||
for_obj_type=for_obj_type,
|
for_obj_type=for_obj_type,
|
||||||
for_obj_id=for_obj_id,
|
for_obj_id=for_obj_id,
|
||||||
by_alias=True,
|
by_alias=True,
|
||||||
exclude_unset=True,
|
exclude_unset=False,
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||||
async def get_archive_content_obj(
|
async def get_archive_content_obj(
|
||||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
obj_id: str = Query(..., min_length=11, max_length=22),
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
by_alias: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
exclude_unset: Optional[bool] = True,
|
exclude_unset: Optional[bool] = True,
|
||||||
|
|||||||
Reference in New Issue
Block a user