Fix for private pastes can be obtained in RAW mode without TS.
This commit is contained in:
parent
c926a58276
commit
a8c8f6de36
@ -1,5 +1,5 @@
|
||||
// Code generated by fileb0x at "2018-05-01 22:56:15.114143898 +0500 +05 m=+0.020887887" from config file "fileb0x.yml" DO NOT EDIT.
|
||||
// modification hash(c89aff9b6b6a650f49dd49d615e3d3e0.e30269e2254cb92c4231bb47f2cedf3a)
|
||||
// Code generated by fileb0x at "2018-05-01 23:06:19.605611358 +0500 +05 m=+0.029101680" from config file "fileb0x.yml" DO NOT EDIT.
|
||||
// modification hash(397d57216a6c1e49feba398620b3b1d5.e30269e2254cb92c4231bb47f2cedf3a)
|
||||
|
||||
package static
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -41,6 +41,7 @@
|
||||
<th>Title</th>
|
||||
<th>Language</th>
|
||||
<th>Pasted on</th>
|
||||
<th>Paste type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -49,10 +50,11 @@
|
||||
<td>{pasteTitle}</td>
|
||||
<td>{pasteLanguage}</td>
|
||||
<td>{pasteDate}</td>
|
||||
<td>{pasteType}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<a class="button" href="/paste/{pasteID}/raw">View raw</a>
|
||||
<td colspan="5">
|
||||
<a class="button" href="/paste/{pasteID}/{pasteTs}raw">View raw</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -103,9 +103,11 @@ func pasteGET(ec echo.Context) error {
|
||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteLanguage}", paste.Language, 1)
|
||||
|
||||
if paste.Private {
|
||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{privateMode}", "Private", 1)
|
||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteType}", "<span class='has-text-danger'>Private</span>", 1)
|
||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteTs}", strconv.FormatInt(paste.CreatedAt.Unix(), 10)+"/", 1)
|
||||
} else {
|
||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{privateMode}", "Public", 1)
|
||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteType}", "<span class='has-text-success'>Public</span>", 1)
|
||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteTs}", "", 1)
|
||||
}
|
||||
|
||||
// Highlight.
|
||||
@ -255,6 +257,21 @@ func pasteRawGET(ec echo.Context) error {
|
||||
return ec.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.")
|
||||
}
|
||||
|
||||
// Check if we have a private paste and it's parameters are correct.
|
||||
if paste.Private {
|
||||
tsProvidedStr := ec.Param("timestamp")
|
||||
tsProvided, err2 := strconv.ParseInt(tsProvidedStr, 10, 64)
|
||||
if err2 != nil {
|
||||
c.Logger.Error().Msgf("Invalid timestamp '%s' provided for getting private paste #%d: %s", tsProvidedStr, pasteID, err2.Error())
|
||||
return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
|
||||
}
|
||||
pasteTs := paste.CreatedAt.Unix()
|
||||
if tsProvided != pasteTs {
|
||||
c.Logger.Error().Msgf("Incorrect timestamp '%v' provided for private paste #%d, waiting for %v", tsProvidedStr, pasteID, strconv.FormatInt(pasteTs, 10))
|
||||
return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
|
||||
}
|
||||
}
|
||||
|
||||
return ec.String(http.StatusOK, paste.Data)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user