|
|
@ -18,18 +18,25 @@ def get_recent(limit=config.recent_pastes):
|
|
|
|
recent_pastes = []
|
|
|
|
recent_pastes = []
|
|
|
|
i = 0
|
|
|
|
i = 0
|
|
|
|
while i < limit and i < len(paths):
|
|
|
|
while i < limit and i < len(paths):
|
|
|
|
with open(paths[i]) as fp:
|
|
|
|
if paths[i].is_file():
|
|
|
|
paste = json.loads(fp.read())
|
|
|
|
with open(paths[i]) as fp:
|
|
|
|
|
|
|
|
try:
|
|
|
|
basename = path.basename(paths[i])
|
|
|
|
paste = json.loads(fp.read())
|
|
|
|
paste['unique_id'] = basename[:-8] if basename.endswith(".expires") else basename
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
paste['content'] = '\n'.join(paste['content'].splitlines()[0:10])
|
|
|
|
i += 1
|
|
|
|
paste['icon'] = common.get_icon(paste['language'])
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
if paste['encrypted']:
|
|
|
|
# Set extra metadata
|
|
|
|
paste['content'] = "[Encrypted]"
|
|
|
|
basename = path.basename(paths[i])
|
|
|
|
|
|
|
|
paste['unique_id'] = basename[:-8] if basename.endswith(".expires") else basename
|
|
|
|
recent_pastes.append(paste)
|
|
|
|
paste['content'] = '\n'.join(paste['content'].splitlines()[0:10])
|
|
|
|
|
|
|
|
paste['icon'] = common.get_icon(paste['language'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Replace preview if encrypted
|
|
|
|
|
|
|
|
if paste['encrypted']:
|
|
|
|
|
|
|
|
paste['content'] = "[Encrypted]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recent_pastes.append(paste)
|
|
|
|
i += 1
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
|
|
|
|
return recent_pastes
|
|
|
|
return recent_pastes
|
|
|
@ -40,7 +47,10 @@ def get_paste(unique_id, key=""):
|
|
|
|
|
|
|
|
|
|
|
|
if file_path is not None:
|
|
|
|
if file_path is not None:
|
|
|
|
with open(file_path, "r") as fp:
|
|
|
|
with open(file_path, "r") as fp:
|
|
|
|
paste = json.loads(fp.read())
|
|
|
|
try:
|
|
|
|
|
|
|
|
paste = json.loads(fp.read())
|
|
|
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
# Check if paste is expired
|
|
|
|
# Check if paste is expired
|
|
|
|
if common.is_expired(paste):
|
|
|
|
if common.is_expired(paste):
|
|
|
|