mirror of
https://github.com/writeas/htmlhouse
synced 2025-07-18 21:08:16 +00:00
Merge branch 'master' of ssh://phabricator.write.as/diffusion/HH/htmlhouse
This commit is contained in:
commit
6dd1787b33
@ -52,6 +52,10 @@ DB_USER=dbuser DB_PASSWORD=pass DB_DB=htmlhouse PRIVATE_KEY=keys/dev PUBLIC_KEY=
|
||||
| `PORT` | Port to run app on | `8080` |
|
||||
| `STATIC_DIR` | Relative dir where static files are stored | `static` |
|
||||
| `AUTO_APPROVE` | Automatically approves public posts | false |
|
||||
| `TWITTER_KEY` | Twitter consumer key | `notreal` |
|
||||
| `TWITTER_SECRET` | Twitter consumer secret | `notreal` |
|
||||
| `TWITTER_TOKEN` | Twitter access token of the posting Twitter account | `notreal` |
|
||||
| `TWITTER_TOKEN_SECRET` | Twitter access token secret of the posting Twitter account | `notreal` |
|
||||
|
||||
### Notes
|
||||
|
||||
|
@ -20,6 +20,13 @@ type config struct {
|
||||
|
||||
AutoApprove bool `env:"key=AUTO_APPROVE default=false"`
|
||||
AdminPass string `env:"key=ADMIN_PASS default=uhoh"`
|
||||
BrowseItems int `env:"key=BROWSE_ITEMS default=10"`
|
||||
|
||||
// Twitter configuration
|
||||
TwitterConsumerKey string `env:"key=TWITTER_KEY default=notreal"`
|
||||
TwitterConsumerSecret string `env:"key=TWITTER_SECRET default=notreal"`
|
||||
TwitterToken string `env:"key=TWITTER_TOKEN default=notreal"`
|
||||
TwitterTokenSecret string `env:"key=TWITTER_TOKEN_SECRET default=notreal"`
|
||||
}
|
||||
|
||||
func newConfig() (*config, error) {
|
||||
|
@ -125,6 +125,9 @@ func addPublicAccess(app *app, houseID, html string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Tweet about it
|
||||
tweet(app, houseID, title)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -293,7 +296,7 @@ func viewHouseStats(app *app, w http.ResponseWriter, r *http.Request) error {
|
||||
func viewHouses(app *app, w http.ResponseWriter, r *http.Request) error {
|
||||
houses, err := getPublicHouses(app)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, ":(")
|
||||
fmt.Printf("Couln't load houses: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -304,7 +307,7 @@ func viewHouses(app *app, w http.ResponseWriter, r *http.Request) error {
|
||||
|
||||
func getPublicHouses(app *app) (*[]PublicHouse, error) {
|
||||
houses := []PublicHouse{}
|
||||
rows, err := app.db.Query("SELECT house_id, title, thumb_url FROM publichouses WHERE approved = 1 ORDER BY updated DESC LIMIT 10")
|
||||
rows, err := app.db.Query(fmt.Sprintf("SELECT house_id, title, thumb_url FROM publichouses WHERE approved = 1 ORDER BY updated DESC LIMIT %d", app.cfg.BrowseItems))
|
||||
switch {
|
||||
case err == sql.ErrNoRows:
|
||||
return nil, impart.HTTPError{http.StatusNotFound, "Return to sender. Address unknown."}
|
||||
|
6
init.sql
6
init.sql
@ -18,3 +18,9 @@ CREATE TABLE `publichouses` (
|
||||
`loves` int(4) NOT NULL,
|
||||
PRIMARY KEY (`house_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tweetedhouses` (
|
||||
`house_id` char(8) NOT NULL,
|
||||
`tweet_id` bigint(20) unsigned NOT NULL,
|
||||
PRIMARY KEY (`house_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
@ -47,7 +47,8 @@
|
||||
<p><strong>Purpose</strong>. To provide a simple HTML testing ground with no cruft or fuss.</p>
|
||||
<p><strong>Editing</strong>. Pages can be edited again from the same computer / browser they were created on. If you clear your browser data (specifically local storage) you will lose this ability.</p>
|
||||
<p><strong>Limitations</strong>. There is currently no way to delete pages.</p>
|
||||
<p><strong>Discovery</strong>. See what others have created on our Twitter account, <a target="_blank" href="https://twitter.com/htmlhouse">@HTMLhouse</a>. Tweet us the URL of any page you create (and whether you want credit) and we'll share it!</p>
|
||||
<p><strong>Discovery</strong>. <a href="/browse">Browse</a> what others have publicly created. Mark your page as <strong>Public</strong> when you publish it to be added!</p>
|
||||
<p><strong>Twitter</strong>. We announce updates and some published pages on <a target="_blank" href="https://twitter.com/htmlhouse">@HTMLhouse</a>.</p>
|
||||
<p><strong>Abuse</strong>. Please don't poop in the pool.</p>
|
||||
|
||||
<h3>Credits</h3>
|
||||
|
45
twitter.go
Normal file
45
twitter.go
Normal file
@ -0,0 +1,45 @@
|
||||
package htmlhouse
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/ChimeraCoder/anaconda"
|
||||
)
|
||||
|
||||
func tweet(app *app, houseID, title string) {
|
||||
// Check for blacklisted titles
|
||||
if title == "HTMLhouse" {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if this has already been tweeted
|
||||
var tweetID int64
|
||||
err := app.db.QueryRow("SELECT tweet_id FROM tweetedhouses WHERE house_id = ?", houseID).Scan(&tweetID)
|
||||
switch {
|
||||
case err != nil && err != sql.ErrNoRows:
|
||||
fmt.Printf("Error selecting from tweetedhouses: %v", err)
|
||||
return
|
||||
}
|
||||
if tweetID != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Post to Twitter
|
||||
text := fmt.Sprintf("\"%s\" on #HTMLhouse - %s/%s.html #html #web #website", title, app.cfg.HostName, houseID)
|
||||
|
||||
anaconda.SetConsumerKey(app.cfg.TwitterConsumerKey)
|
||||
anaconda.SetConsumerSecret(app.cfg.TwitterConsumerSecret)
|
||||
api := anaconda.NewTwitterApi(app.cfg.TwitterToken, app.cfg.TwitterTokenSecret)
|
||||
|
||||
t, err := api.PostTweet(text, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("Error posting tweet: %v", err)
|
||||
}
|
||||
|
||||
// Mark it as "tweeted"
|
||||
_, err = app.db.Exec("INSERT INTO tweetedhouses (house_id, tweet_id) VALUES (?, ?)", houseID, t.Id)
|
||||
if err != nil {
|
||||
fmt.Printf("Error noting house tweet status: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user