Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8280e5b0ad | ||
|
|
ae97fbe025 |
@@ -68,6 +68,9 @@ func (c *sqliteCache) Messages(topic string, since sinceTime) ([]*message, error
|
|||||||
if err := rows.Scan(&id, ×tamp, &msg); err != nil {
|
if err := rows.Scan(&id, ×tamp, &msg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if msg == "" {
|
||||||
|
msg = " " // Hack: never return empty messages; this should not happen
|
||||||
|
}
|
||||||
messages = append(messages, &message{
|
messages = append(messages, &message{
|
||||||
ID: id,
|
ID: id,
|
||||||
Time: timestamp,
|
Time: timestamp,
|
||||||
|
|||||||
@@ -60,14 +60,20 @@
|
|||||||
|
|
||||||
<h2 id="publish" class="anchor">Publishing messages</h2>
|
<h2 id="publish" class="anchor">Publishing messages</h2>
|
||||||
<p>
|
<p>
|
||||||
Publishing messages can be done via PUT or POST using. Topics are created on the fly by subscribing or publishing to them.
|
Publishing messages can be done via PUT or POST. Topics are created on the fly by subscribing or publishing to them.
|
||||||
Because there is no sign-up, <b>the topic is essentially a password</b>, so pick something that's not easily guessable.
|
Because there is no sign-up, <b>the topic is essentially a password</b>, so pick something that's not easily guessable.
|
||||||
</p>
|
</p>
|
||||||
<p class="smallMarginBottom">
|
<p class="smallMarginBottom">
|
||||||
Here's an example showing how to publish a message using <tt>curl</tt>:
|
Here's an example showing how to publish a message using <tt>curl</tt> (via POST):
|
||||||
</p>
|
</p>
|
||||||
<code>
|
<code>
|
||||||
curl -d "long process is done" ntfy.sh/mytopic
|
curl -d "Backup successful 😀" ntfy.sh/mytopic
|
||||||
|
</code>
|
||||||
|
<p class="smallMarginBottom">
|
||||||
|
And another one using PUT:
|
||||||
|
</p>
|
||||||
|
<code>
|
||||||
|
echo -en "\u26A0\uFE0F Unauthorized login" | curl -sT- ntfy.sh/mytopic
|
||||||
</code>
|
</code>
|
||||||
<p class="smallMarginBottom">
|
<p class="smallMarginBottom">
|
||||||
Here's an example in JS with <tt>fetch()</tt> (see <a href="https://github.com/binwiederhier/ntfy/tree/main/examples">full example</a>):
|
Here's an example in JS with <tt>fetch()</tt> (see <a href="https://github.com/binwiederhier/ntfy/tree/main/examples">full example</a>):
|
||||||
|
|||||||
@@ -243,6 +243,9 @@ func (s *Server) handlePublish(w http.ResponseWriter, r *http.Request, v *visito
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m := newDefaultMessage(t.id, string(b))
|
m := newDefaultMessage(t.id, string(b))
|
||||||
|
if m.Message == "" {
|
||||||
|
return errHTTPBadRequest
|
||||||
|
}
|
||||||
if err := t.Publish(m); err != nil {
|
if err := t.Publish(m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user